我有一个r小册子地图,有多个图层,每个图层都可以检查或取消选中。我试图找到一种方法来选择全部/取消选择所有选项。
下面是我的代码,其中叠加是反应组。 df()是一个反应数据帧myLocation()是一个反应位置(long,lat)
因此,在右上角的地图中,我想要选择全部/取消选择所有选项
groups <- reactive({as.character(unique(df()$Folder))})
groupColors <- reactive({
colorFactor(palette = rainbow(length(groups())),
domain = df()$Folder)
})
output$mymap <- renderLeaflet({
leaflet() %>%
addTiles() %>%
leaflet::addMarkers(lng=c(myLocation()[1]), lat=c(myLocation()[2]),
popup = paste("Lat/Long: ",myLocation()[2],"/",myLocation()[1]),
popupOptions = popupOptions(maxWidth = 1000, closeOnClick = TRUE))
%>%
############more code here
#this section is where a select all/ deselect option has to be placed
addLayersControl(overlayGroups=groups(),options =
layersControlOptions(collapsed = TRUE))
})
关注shiny教程...尝试使用leafletProxy
修改现有地图,并使用传单中的hideGroup()
函数添加/删除整个组。