How to correctly clearShapes in Leaflet in a Shiny app
<p>Note that this question has been posted <a href="https://groups.google.com/forum/#!topic/shiny-discuss/l9K1ToSs3wk" rel="nofollow">at the R Shiny Google Group</a>:</p>

<p>Following the <a href="https://rstudio.github.io/leaflet/shiny.html" rel="nofollow">Leaflet for R/ Shiny Integration documentation</a>, I'm getting unwanted/ unexpected behavior with the leafletProxy function.</p>

<p>In the app below, I'd expect the circle markers to appear/ disappear as the input$choices changes.</p>

<p>The reactive df 'filteredData' seems to be working correctly.</p>

<p>Am I incorrectly using leafletProxy() or clearShapes()?</p>

<pre><code>library(shiny)
library(dplyr)
library(leaflet)


my_df &lt;- data.frame(lat = 34.72 + rnorm(1000, sd = .18), 
                    lng = -92.5 + rnorm(1000, sd = .33), 
                    category = c(rep("A", 300), rep("B", 300), rep("C", 400)))

ui &lt;- bootstrapPage(
  tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
  leafletOutput("map", height = '100%', width = '100%'),
  absolutePanel(top = 10, right = 10, 
                checkboxGroupInput("choices", "Choices", choices =     list("A","B","C"), selected = c("A","B","C")),
                verbatimTextOutput("my_rows")


  )
)


server &lt;- function(input, output) {

  filteredData &lt;- reactive( my_df %&gt;% filter(category %in% input$choices) )

    output$map &lt;- renderLeaflet({ leaflet() %&gt;% addTiles() %&gt;% setView(lat =     34.72, lng = -92.5, zoom = 9) })

    observe({

      leafletProxy("map", data = filteredData()) %&gt;% clearShapes() %&gt;% addCircleMarkers(radius = 6, weight = 1, fillColor = "red", fillOpacity = 0.3)

    })

    output$my_rows &lt;- renderPrint({ filteredData() %&gt;% nrow() })
}

shinyApp(ui = ui, server = server)
</code></pre>