R Leaflet (CRAN) - how to register clicking off a marker

后端 未结 1 1216
离开以前
离开以前 2021-01-13 20:18

Using the RStudio Leaflet package in a shiny app I\'ve been able to achieve all the functionality I\'ve looked for except deselecting a marker object once it has been clicke

相关标签:
1条回答
  • 2021-01-13 21:02

    You could use a reactiveValues to store the clicked marker and reset it whenever the user clicks on the map background:

    server <- shinyServer(function(input, output) {
      data <- reactiveValues(clickedMarker=NULL)
      # produce the basic leaflet map with single marker
      output$map <- renderLeaflet(
        leaflet() %>%
          addProviderTiles("CartoDB.Positron") %>%
          addCircleMarkers(lat = 54.406486, lng = -2.925284)    
      )
    
      # observe the marker click info and print to console when it is changed.
      observeEvent(input$map_marker_click,{
                   data$clickedMarker <- input$map_marker_click
                   print(data$clickedMarker)}
      )
      observeEvent(input$map_click,{
                   data$clickedMarker <- NULL
                   print(data$clickedMarker)})
    })
    
    0 讨论(0)
提交回复
热议问题