输出未显示在 Shiny 中

Output not showing in Shiny

我编写了以下代码以在 R 脚本中将输出显示为 GGmap。代码运行良好,但未显示输出。 任何人都可以提供帮助。我一直试图找出错误,但仍然无法解决。如果有人能帮助我,我将不胜感激。提前谢谢你。

    #### Below Code ####
    ## Libraries

   library(ggmap)
   library(shiny)
            
    bbox = c(left=-95.8, bottom=29.4, right=-95.0, top=30.0)
    map <- get_stamenmap(bbox, zoom = 10, source="stamen")
    
    ui <- fluidPage(
      titlePanel("Crime Offences"),
      sidebarPanel('Navigator',
                   checkboxGroupInput("crime_type", label = "Select offense type:",
                                      choices = list("Aggravated Assault" = 'aggravated assault',
                                                     "Auto Theft" = 'auto theft',
                                                     "Burglary" = 'burglary',
                                                     "Murder" = 'murder',
                                                     "Rape" = 'rape',
                                                     "Robbery" = 'robbery'),
                                      selected = 'Intel'),
                   dateRangeInput("date_range", label = "Select time period:",
                                  start = "2010-01-01",
                                  end = "2010-08-31",
                                  min = "2010-01-01",
                                  max = "2010-08-31",
                                  format = "mm/dd'yy",
                                  separator = " - ")),
      
      
      mainPanel('Crime Data Information',
                plotOutput("crime_data_final")),
      position = 'left')
    
    
    server <- function(input, output){
      output$crime_data_final <- renderPlot(
        
        ggmap(map) + stat_density2d(data = subset(crime_data, offense == input$crime_type),
                                    aes(x = "date", y = input$crime_type) +
          scale_fill_gradient(low = "green", high = "red") +
          scale_alpha_continuous(range = c(0, 0.8)) +
          geom_point(data = subset(crime_data, offense == input$crime_type),
                     aes(x = "date", y = input$crime_type), size = 0.5) + 
          guides(fill = FALSE, alpha = FALSE) +
          ggtitle('Crime in Houston TX',
                  subtitle = 'Murders are concentrated around two areas in the city'))
      )
    }
    
    ## Executing the app
    
    shinyApp(ui = ui, server = server)
    
    

下面是输出

由于你没有提供crime_data,测试比较困难,尝试更换日期格式:

 dateRangeInput("date_range", label = "Select time period:",
                                  start = "2010-01-01",
                                  end = "2010-08-31",
                                  min = "2010-01-01",
                                  max = "2010-08-31",
                                  format = "mm/dd'yy",
                                  separator = " - "))

来自

 dateRangeInput("date_range", label = "Select time period:",
                                  start = "2010-01-01",
                                  end = "2010-08-31",
                                  min = "2010-01-01",
                                  max = "2010-08-31",
                                  format = yyyy-mm-dd",
                                  separator = " - "))

问题是 datePicker 不允许您的开始日期,这会破坏服务器和 ui 之间的某些东西 ui 尝试将您的 datepicker 更改为这样的东西。

dateRangeInput("date_range", label = "Select time period:",
                                start = "2010-01-01",
                                end = "2010-08-31",
                                min = "2009-31-12",
                                max = "2010-08-31",
                                format = "mm/dd'yy",
                                separator = " - ")