Hello,
I am new in using R studio and I am building an R shiny application with Leaflet.
My problem is that I can put my addCircleMarkers in the output$map and it works but it takes a lot of time and while trying to put in an observer using leafletProxy the circles just doesn't appear at all .
Therefore, I used addCircleMarkers in observer for an other map and it works.
Can you please help me find the problem so I can put it in an observer ?
Here is my code
output$mapDepartement <- renderLeaflet({
palInfectionF <- colorBin("Greens", domain = dataDepartementCasTotalRecent()$tauxIncidence,bins = 6)
leaflet(dataDepartementCasTotalRecent()) %>%
addTiles() %>%
addLegend("bottomleft", pal = palInfectionF, values = ~dataDepartementCasTotalRecent()$tauxIncidence,
title = "<small>Taux d'incidence <br/>par 100 000 habitants</small>",group = "Cas") %>%
addLayersControl(
position = "bottomleft",
overlayGroups = c("Cas","Tests","Hospitalisations","Deces à l'hôpital"),
options = layersControlOptions(collapsed = FALSE,draggable = TRUE)) %>%
addProviderTiles(providers$CartoDB.Positron) %>%
fitBounds(~-100,-60,~60,70) %>%
hideGroup(c("Hospitalisations","Tests","Deces à l'hôpital")) %>%
setView(lng = -1.713749,lat = 47.02764, zoom = 5.6)
})
observe({
palInfectionF <- colorBin("Greens", domain = dataDepartementCasTotalRecent()$P)
leafletProxy("mapDepartement",data = dataDepartementCasTotalRecent()) %>%
clearMarkers() %>%
addCircleMarkers(layerId = ~nom_departement,weight = 1, radius = ~P^(1/4),
fillOpacity = 0.7, color = "#777777", group = "Cas",fillColor = ~palInfectionF(tauxIncidence),
label = sprintf("<h4>%s</h4>Infections de 30 derniers jours : <B>%s</B><br/>Taux d'incidence de 30 derniers jours: <B>%s</B>",
dataDepartementCasTotalRecent()$nom_departement,
numberF(dataDepartementCasTotalRecent()$P),percentF(dataDepartementCasTotalRecent()$tauxIncidence)) %>% lapply(htmltools::HTML),
labelOptions = labelOptions(width = "50px",
style = list("font-weight" = "normal", padding = "3px 8px", "color" = lkp_blue),
textsize = "15px", direction = "auto"))
})
Thank you for helping !