使用R Shiny和Leaflet的动态地图

时间:2016-12-26 23:37:19

标签: r shiny leaflet

我在使用R闪亮和传单渲染交互式地图时遇到问题。我能够第一次渲染绘图,但是当我更改某些输入(在这种情况下输入$ inputTime)时,地图(输出$ main_map)会变灰。

UI.r

library(shiny)
library(leaflet)
ui <- fluidPage(
  includeCSS("style.css"),
  titlePanel("Welcome to the app!"),

  sidebarLayout(
    sidebarPanel(
      radioButtons("inputCrimeRate", 
                   "Crime Rate",
                   choices = c("All", "High", "Medium", "Low"),
                   selected = "All"),
      radioButtons("inputTime", 
                   "Time of the day",
                   choices = c("All_day", "AM", "PM"),
                   selected = "All_day",inline = TRUE),
      selectInput("inputCrimeType",
                  "Crime Type",
                  choices = c("Theft", "Assault", "DUI"))
      #actionButton(inputId = "go",label="update")
      ),

    mainPanel(
      renderText(output$test),
      leafletOutput("main_map"),
      "test_014",
      br()
    )
  )
)

server.r

library(shiny)
library(ggmap)
library(ggplot2)
library(leaflet)
server <- function(input,output)
{
  geocodeQueryCheck()
  #load("app2/data03.Rda")

  #main map
  output$main_map <- renderLeaflet({ 

                                  time <- input$inputTime

                                  if(time == "All_day")
                                    {data05 <- data04}
                                  else if (time == "AM")
                                  {data05 <- data04[data04$Occured.Time2 == "AM",]}
                                  else if (time == "PM")
                                  {data05 <- data04[data04$Occured.Time2 == "PM",]}



                                  leaflet(data05) %>% 
                                  addTiles() %>% 
                                  setView(-84.5092756,39.1268475,zoom=12) %>% 
                                  addCircles(popup=data04$Offense, weight=2,radius=10)

                            }
                          )


}

0 个答案:

没有答案