library(shiny)
library(leaflet)
output$map <- renderLeaflet({
m<-leaflet() %>%
addProviderTiles(providers$OpenStreetMap,
options = providerTileOptions(noWrap = TRUE))%>%
setView(lng =-73.958091, lat =40.643767, zoom= 12)
observe({ click = input$map_click
if(is.null(click))
return()
else
click= data.frame(click[1:2])
# if the object v does not exist store the click information in the object "v"
if(exists("v")==F){
leafletProxy("map") %>%
addMarkers(data = click) ->>v
v<<-data.frame(v$x$limits)}
#if object v exists store click information on object "w"
if(exists("v")==T) {leafletProxy("map") %>%
addMarkers(data = click) ->>w}
w<<-data.frame(w$x$limits)
This code creates a marker each time the map is clicked, but how do I store the information for each click in a different variable? I need to store the latitude and longitude of 1 click on one object and another click on another object
> w
lat lng
1 40.643767 -73.958091
2 40.643767 -73.958091
> v
data frame with 0 columns and 0 rows
the w object stores the information I want but the v doesn't.. Why does it happen?