首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在leafletProxy()中绘制整个数据帧的数据?

如何在leafletProxy()中绘制整个数据帧的数据?
EN

Stack Overflow用户
提问于 2018-12-11 21:32:53
回答 1查看 298关注 0票数 1

我正在使用RStudio中的R并创建了一个闪亮的仪表板。在仪表板中,我使用leaflet()函数来绘制地图。现在我正试着在地图上画上标记物,标明芝加哥的犯罪情况。我正在使用selectInput()和sliderInput()函数来选择不同的犯罪类型、地点和年份。如果我在输入字段中选择了一些东西,那么这些标记就会显示在芝加哥地图上,而且效果很好。但我希望当我启动这个闪亮的应用程序时,所有的标记都会显示出来,而不会基于selectInput()进行过滤。这是我的ui.R代码:

  tabItem(tabName = "map",
    div(class="outer",
    tags$head(
    tags$style(type = "text/css", "#map {height: calc(100vh - 80px) !important;}"))),

    leafletOutput("map", width = "100%", height = "100%"),

    absolutePanel(id = "mapControls", fixed = TRUE, draggable = TRUE, top = 150, left = "auto", right = 15, bottom = "auto", width = 200, height = "auto",

    selectInput("mapCrimeType", label= "Select Crime Type", choices = unique(cc$Primary.Type), multiple = TRUE),

    selectInput("mapLocation", label= "Select Location", choices = unique(cc$Location.Description), multiple = TRUE),

    sliderInput("mapYear", label = "Select Year", min = 2001, max = 2016, step = 1, sep = '', value = c(2001,2016))

          )
  ),

这是我的服务器.R代码:

server <- function(input, output) {

  ### Draw Map ###
  output$map = renderLeaflet({
      leaflet() %>% 
      addProviderTiles(providers$Esri.WorldStreetMap) %>% 
      setView(lng = -87.6105, lat = 41.8947, zoom=11)
  }) 

  reactMap = reactive({
    cc %>% 
    filter(Primary.Type %in% input$mapCrimeType &
             Location.Description %in% input$mapLocation &
             Year %in% cbind(input$mapYear[1],input$mapYear[2]))
  })

  observe({
    proxy = leafletProxy("map", data = reactMap()) %>%
      clearMarkers() %>%
      clearMarkerClusters() %>%
      addCircleMarkers(clusterOptions = markerClusterOptions(),
                       lng =~ Longitude, lat =~ Latitude, radius = 5, group = 'Cluster', 
                       popup =~ paste('<b><font color="Black">', 'Crime Information', 
                      '</font></b><br/>', 'Crime Type:', Primary.Type,'<br/>',
                      'Date:', Date,'<br/>', #'Time:', Time,'<br/>',
                      'Location:', Location.Description,'<br/>', 'Block:', Block, '<br/>', 'Arrest:', Arrest, '<br/>'))
  })

我想我必须在server.R文件内的反应函数中更改一些东西。我希望有人能帮助我。

更新:使用此数据集:https://www.kaggle.com/currie32/crimes-in-chicago

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53725226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档