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


using rstudio leaflet package in shiny app i've been able achieve functionality i've looked except deselecting marker object once has been clicked on.

more specifically, input$map_click_id value set null before markers clicked. upon clicking marker updated data (id, lat, lng, nonce) marker. set map when user clicks on area of map not marker, input$map_click_id reset null until marker clicked.

i've tried number of work around solutions such comparing click times marker clicks , map clicks, marker click variable, once set non-null value, updated everytime map clicked, regardless of whether on marker or not, doesn't work.

any here appreciated! below minimal reproducable example. in case marker info print console when clicked, , null returned console when non-marker area of map clicked.

library(leaflet) library(shiny)  # set basic ui ui <- fluidpage(   leafletoutput("map") )  server <- shinyserver(function(input, output) {    # produce basic leaflet map single marker   output$map <- renderleaflet(     leaflet() %>%       addprovidertiles("cartodb.positron") %>%       addcirclemarkers(lat = 54.406486, lng = -2.925284)    )    # observe marker click info , print console when changed.   observeevent(input$map_marker_click,                print(input$map_marker_click)                )  })   shinyapp(ui, server) 

this appears same question asked here there no answer this, thought i'd try again.

you use reactivevalues store clicked marker , reset whenever user clicks on map background:

server <- shinyserver(function(input, output) {   data <- reactivevalues(clickedmarker=null)   # produce basic leaflet map single marker   output$map <- renderleaflet(     leaflet() %>%       addprovidertiles("cartodb.positron") %>%       addcirclemarkers(lat = 54.406486, lng = -2.925284)       )    # observe marker click info , print console when 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)}) }) 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -