I am creating a Shiny app meant to display a choropleth map.
I would like to change reactivly the values to show on my map with radiobuttons.
It worked fine with normal button, but i am struggling with the radiobutton now, any ideas?
you can download the data via this link : https://www.data.gouv.fr/fr/datasets/r/8b004f01-e7af-40d2-ab4a-8108a8bd24b2
here is my code so far :
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)