in R's version of leaflet, How can I obtain the lat longs of where markers have been dragged to?
library(shiny)
library(leaflet)
library(tidyverse)
ui = fluidPage(
leafletOutput('map'),
textOutput('dragEndLocation')
)
server = function(input, output, session){
output$map = leaflet() %>%
addTiles() %>%
addMarkers(lat = 1,lng = 2, options = markerOptions(draggable = TRUE)
output$dragEndLocation = renderText({
???
})
}
I see in javascript leaflet, there is an event called dragEnd
that you can listen for, but it is not implemented in R leaflet. (leaflet.js - Set marker on click, update position on drag)
This person (How to update coordinates after dragging a marker in leaflet shiny?) made a hack-y workaround by listening for input$map_marker_mouseout
and then checking if the lat long has changed, but it is not ideal. When you drag a marker very quickly, mouseout will register several times. It is not a problem for this minimal working example, but for my actual application which wants to a slower script after drag end, it makes this workaround very buggy and slow.
Any ideas?