title: R leaflet - How to wait for `map_shape_click` only
body: <p>Using <code>leaflet</code> mouse-events, a click on a shapefile, also triggers a click on the map, so the green lines in the example are drawn immediately.</p>
  
  <p>How can I wait for a click on one of the shapefiles, to remove the clicked Line  and ignore map-clicks for that, but when I click on the map (and not a shapefile), the green lines show up?</p>
  
  <p>Or how can I get a <code>input$map_shape_click</code> only?</p>
  
  <pre><code>library(shiny)
  library(leaflet)
  library(sp)
  
  ## DATA
  x &lt;- c(1,5,4,8); y &lt;- c(1,3,4,7)
  data = sp::SpatialLines(list(
    sp::Lines(sp::Line(cbind(x,y)), ID="a"),
    sp::Lines(sp::Line(cbind(rev(x)*1.1,y)), ID="b")), 
    CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"))
  
  data = SpatialLinesDataFrame(data, data = data.frame(
    id = 1:length(data)), match.ID = F)
  data1 = SpatialLinesDataFrame(data, data = data.frame(
    id = 1:length(data)), match.ID = F)
  
  ## UI
  ui = fluidPage(
    leafletOutput("map")
  )
  
  ## SERVER
  server &lt;- shinyServer(function(input, output, session) {
  
    output$map &lt;- renderLeaflet({
      leaflet(options = leafletOptions(doubleClickZoom= FALSE)) %&gt;% 
        addTiles() %&gt;% 
        addPolylines(data = data, smoothFactor = 10, opacity = 1, color = "blue",
                     layerId = as.character(data$id),
                     highlightOptions = highlightOptions(color = "white",
                                                         weight = 5, bringToFront = F, opacity = 1)
        )
    })
  
    observeEvent(input$map_shape_click, {
      cat("Shape is Clicked \n")   
      proxy &lt;- leafletProxy("map")
      proxy %&gt;% removeShape("1")
    })
  
    observeEvent({ input$map_click }, {
      cat("Map Clicked \n")
      proxy &lt;- leafletProxy("map")
      proxy %&gt;%       addPolylines(data = data, smoothFactor = 10, opacity = 1, color = "green",
                                   layerId = as.character(data$id))
  
    })
  
  })
  
  shinyApp(ui, server)
  </code></pre>