【发布时间】:2019-08-02 20:47:31
【问题描述】:
我正在创建一个用于显示等值线地图的 Shiny 应用程序。
我想用单选按钮重新更改要在我的地图上显示的值。
普通按钮效果很好,但我现在正在努力使用单选按钮,有什么想法吗?
您可以通过此链接下载数据:https://www.data.gouv.fr/fr/datasets/r/8b004f01-e7af-40d2-ab4a-8108a8bd24b2
这是我目前的代码:
sData <- readOGR(dsn = " Set your path to the downloaded Data here")
ui<- bootstrapPage(
leafletOutput("mymap"),
absolutePanel(top = 10,
right = 10,
radioButtons("radio", h3("Indicateurs de mobilité"),
choices = list("AttrOne" = "Attr1",
"AttrTwo" = "Attr2")))
)
server <- function(input, output, session) {
v <- reactiveValues(data = sData$numdep)
observeEvent(input$Attr1, {
v$data <- sData $numdep
})
observeEvent(input$Attr2, {
v$data <- sData $insee
})
output$mymap <- renderLeaflet({
leaflet(sData) %>%
addProviderTiles(
providers$"CartoDB.DarkMatter") %>%
addPolygons(
fillColor = ~colorBin(palette = "YlOrRd",
bins = getBreaks(v$data,
nclass = 6,
method = "fisher-jenks"),
domain = v$data
)(v$data),
weight = 1,
opacity = 0.3,
color = "white",
fillOpacity = 0.3)
})
}
shinyApp(ui = ui, server = server)
【问题讨论】:
标签: r shiny radio-button leaflet choropleth