Hello,
I am trying to update the colors of markers depending on input without removing markers and adding them again with a new color.
I have found these fonctions below, BUT I have clusterOptions in my addCircleMarkers function (>250k markers) and it seems that the functions developed below can not support clusterOptions with LeafletProxy.
Problem with the updated LayerId and the created clusterId ?
rstudio:main
← edwindj:master
opened 12:31AM - 26 Nov 18 UTC
I have added three new methods that allow for style changes of already rendered … choropleths and circlemarkers. Its usage is typically with leafletproxy in shiny and is a fix for issue #496.
## Example
A minimal example is included in inst/examples/setStyle.R
```r
library(shiny)
library(leaflet)
coor <- sp::coordinates(gadmCHE)
ui <- fluidPage(
leafletOutput("map"),
radioButtons("color", "Color", choices = c("blue", "red", "green")),
sliderInput("radius", "Radius", min = 1, max = 30, value=5, animate = TRUE)
)
server <- function(input, output, session){
output$map <- renderLeaflet({
leaflet(data=gadmCHE) %>%
addPolygons(layerId = ~NAME_1, weight = 1) %>%
addCircleMarkers(layerId = gadmCHE$NAME_1, data = coor, weight = 1)
})
observe({
leafletProxy("map", data = gadmCHE) %>%
setCircleMarkerRadius(gadmCHE$NAME_1, input$radius)
})
observe({
leafletProxy("map", data = gadmCHE) %>%
setShapeStyle(layerId = ~NAME_1, fillColor=input$color, color = input$color) %>%
setCircleMarkerStyle(layerId = ~NAME_1, fillColor = input$color, color = input$color)
})
}
shinyApp(ui, server)
```
Thanks.
system
Closed
July 3, 2021, 12:16pm
2
This topic was automatically closed 54 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.