I'm working with Leaflet in RStudio. Now, I would like to capture the mouseclick and get its coordinates on a map. Something like this .
Do you know how to adapt that code for leaflet in R?
If you want to add the Shiny library you can use input$map_click, where map is the name of your map.:
library(shiny)
library(leaflet)
shinyApp(
ui = fluidPage(
leafletMap(
"map", "100%", 400,
initialTileLayer = "//{s}.tiles.mapbox.com/v3/jcheng.map-5ebohr46/{z}/{x}/{y}.png",
initialTileLayerAttribution = HTML('Maps by <a href="http://www.mapbox.com/">Mapbox</a>'),
options=list(
center = c(37.45, -93.85),
zoom = 4,
maxBounds = list(list(17, -180), list(59, 180))))),
server = function(input, output, session){
map = createLeafletMap(session, 'map')
observe({
click<-input$map_click
if(is.null(click))
return()
text<-paste("Lattitude ", click$lat, "Longtitude ", click$lng)
map$showPopup( click$lat, click$lng, text)
})
}
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.