clearShapes() not working — leaflet() for R

前端 未结 1 1526
耶瑟儿~
耶瑟儿~ 2020-12-19 09:50

I cannot figure out why clearshapes() is not working in my leaflet shiny program. I am trying to remove the existing circles and replace with a category that is

相关标签:
1条回答
  • 2020-12-19 10:36

    Looks like there is an issue when filteredData() is empty. You can trying adding an 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 the data points that have a selected Source, you might want to use %in% instead of == in your filtering:

    df[as.character(df$Source) %in% input$set, ]
    
    0 讨论(0)
提交回复
热议问题