[R-sig-Geo] reactive map on shiny

basile.lenormand b@@||e@|enorm@nd @end|ng |rom protonm@||@com
Mon Jan 3 13:35:49 CET 2022


It is me again, sorry I am a bit lost.

I am trying to make my polygones reacting to my widgets. But I do not find how to make polygones react to sliders. I reached to do it for the second slider, but not for the others widgets. I do not reach to display the checkbox legend neither.

I do not understand when I have to use reactives, also I do not find the function that plot the output of the widget for the observer on the map. Do I have to use renderPlot?

If you got some time I would be pleased,
have a great day,
Basile

Here is my code:

ui <- bootstrapPage(
titlePanel("Incendie en PACA à l'échelle des communes"),
sidebarLayout(

sidebarPanel(
helpText("Créez votre propre visualisation du risque"),
selectInput("climate",
label = "Choose a variable to display",
choices = spdf$koppen,
selected = "Csa_Clipped"),
sliderInput("range1", "surface brûlée en hectare", min(spdf$V11), max(spdf$V11),
value = range(spdf$V11), step = 2500),
sliderInput("range2", "Nombre d'incendie", min(spdf$n), max(spdf$n),
value = range(spdf$n), step = 2),
checkboxInput("legend", "Show legend", TRUE)),

mainPanel(
textOutput("selected_var"),
leafletOutput("map",width = 600, height = 300)),
)
)

server <- function(input, output, session) {

output$map <-renderLeaflet({
leaflet() %>%
addTiles(group = "OSM") %>%
#fitBounds(~min(long), ~min(lat), ~max(long), ~max(lat))%>%
addPolygons(
data=my_summary_84,
fillColor =~colorQuantile("YlOrRd", spdfV11),
fillOpacity = 0.7,
popup = ~Nom_Commun) %>%
setView(lat= 44.2, lng=5.9, zoom=5)
})

df_filtered <- reactive({
spdf[spdf >= input$range2, ]
})

observe({
leafletProxy(mapId = "map", data = df_filtered()) %>%
clearShapes() %>% ## clear previous markers
addPolygons()
})

}
shinyApp(ui, server)

Sent with [ProtonMail](https://protonmail.com) Secure Email.
	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list