I want to learn how to erase a marker

shiny
leaflet
rstudio
rstudioconnect

#1

I would like to learn how to delete a marker one by one, for example if a user creates a new marker in the map and clicks on the button that will be called “Delete a marker”, at the end it deletes a clicked marker.

You could tell me about some method to delete a marker one by one or they would have some code or a Github repository, I just need to know or give me an idea of how to delete it.

For example I have a code but I would like to know how it will work to erase a marker one by one …

# Server.R
#...
#...
# Events: Add and Clear markers hospitals 
  v <- reactiveValues(msg = "")
  
  df_r <- reactiveValues(new_data = datf)
  clicked_markers <- reactiveValues(clickedMarker = NULL) 
  observeEvent(input$map_click, { 
    
    click<- input$map_click 
    click_lat <- click$lat
    click_long <- click$lng
    
    clicked_markers$clickedMarker <- c(clicked_markers$clickedMarker, 1) 
    id <- length(clicked_markers$clickedMarker) 
    
    v$msg <- paste("Add marker in: ",input$map_click$lat, ",", input$map_click$lng)
    
    if (input$addMarker) {
      leafletProxy("map") %>%
        addMarkers(lng = click$lng, lat = click$lat, layerId = id) #layerid
      
        df_r$new_data <- rbind(rep(NA,ncol(datf)), df_r$new_data)
        df_r$new_data$longitude[1] <- click_long
        df_r$new_data$latitude[1] <- click_lat
        df_r$new_data$existing[1] <- click_long
        
        #if (input$removeMark) {
          #leafletProxy("map", session) %>%
        #         removeMarker(input$map_click)
          
         # }
        
        }
  })
  
  output$tabledata <- renderDataTable({
    df_r$new_data
    
    })
  
  observeEvent(input$map_zoom, {
    v$msg <- paste("Zoom changed to", input$map_zoom)
  })
  observeEvent(input$map_bounds, {
    v$msg <- paste("Bounds changed to", paste(input$map_bounds, collapse = ", "))
  })
  observeEvent(input$clearMarkers, {
    
    leafletProxy("map") %>% clearMarkers()
  })
  
  observeEvent(input$removeMark, {
    if (input$removeMark) {
      leafletProxy("map") %>%
        removeMarker(¿?) ## 
      
    }
  })
  
  output$message <- renderText(v$msg)