【发布时间】:2019-05-12 12:11:00
【问题描述】:
我在 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))
)
),
这是我的 server.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 文件中的响应函数中的某些内容。我希望有人能帮助我。
【问题讨论】:
标签: r dictionary shiny leaflet react-leaflet