请参阅以下 MWE:
library(shiny)
library(leaflet)
ui <- fluidPage(leafletOutput("mymap"))
server <- function(input, output, session) {
output$mymap <- renderLeaflet({
leaflet() %>%
addProviderTiles(
providers$Stamen.TonerLite,
group = 'stamen',
options = providerTileOptions(noWrap = TRUE)
) %>%
addProviderTiles(providers$CartoDB.Positron, group = 'cartodb') %>%
addLayersControl(baseGroups = c('stamen', 'cartodb'),
position = 'bottomleft')
})
}
shinyApp(ui, server)
LayerControl (addLayersControl) 的标准行为是在用户悬停图标后出现。相反,我想在单击后查看图层选项。标准 addLayersControl 函数不提供此类功能。有人知道解决方法吗?