ClearShapes () not working - leaflet () for R

I cannot understand why clearshapes() does not work in my brilliant program. I am trying to delete existing circles and replace with a category that is selected based on the input checkbox that I have. However, it happens that new circles overlap over existing ones.

Has anyone come across this before?

 df = read.csv("mappingData.csv",header=T, sep =",") ui = fluidPage( checkboxGroupInput("set", label = "Pothole Reported by:", choices = list("Citizens Connect App" = "Citizens Connect App", "City Worker App" = "City Worker App", "Constituent Call" = "Constituent Call", "Self Service" = "Self Service", "Employee Generated" = "Employee Generated", "Not Available (Cambridge)" = "")), verbatimTextOutput("value"), leafletOutput("map") ) server <- function(input, output) { filteredDataCheck <- reactive({ # subset(df, Source == input$set) print(input$set) }) output$value <- renderPrint ({ filteredDataCheck() }) filteredData <- reactive({ df[as.character(df$Source) == input$set, ] }) output$map <- renderLeaflet ({ leaflet(df) %>% setView(-71.083, 42.353, 13) %>% addProviderTiles("Stamen.TonerLite", options = providerTileOptions(noWrap=T)) }) observe({ leafletProxy("map", data = filteredData() ) %>% clearShapes() %>% addCircles(radius = 1, color = "red", group = "circles") %>% clearShapes() }) } shinyApp(ui = ui, server = server) 
+4
source share
1 answer

There seems to be a problem when filteredData() empty. You can try adding if / else:

 if(nrow(filteredData())==0) { leafletProxy("map") %>% clearShapes()} else { leafletProxy("map", data = filteredData() ) %>% clearShapes() %>% addCircles(radius = 1, color = "red", group = "circles") } 

Also, if you want all data points to have the selected Source , you can use %in% instead of == in your filtering:

 df[as.character(df$Source) %in% input$set, ] 
+11
source

All Articles