Now what I want to achieve ultimately, is a leaflet map on which users(multiple users accessing this web app at the same time) can pinpoint a location on it, and others can see the new pinpoints directly without causing the whole website to redraw. Besides, the data saved on the websites should be able to kept, so that the second time when any users visit the website, they should still be able to see previous points.
I understand that using leafletProxy()
would be useful, but in terms of saving every user's data to "global data", I'm not sure what to do.
Here is a demi-code, hopefully to show what I want to achieve:
in global.R
:
library(shiny)
library(leaflet)
library(magrittr)
library(ggmap)
library(htmltools)THIS VARIABLE IS TO SAVE ALL USERS' DATA!
FULL_DATA <- data.frame("name" = "Initialization", "lon" = -71.8, "lat" = 44.3)
in server.R
:
server <- function(input, output, session) {
default_map <- leaflet() %>%
addTiles()
output$map <- renderLeaflet(default_map)An submit button for when user is done entering location
observeEvent(input$submit_loc, {
temp_loc <- isolate(input$location)
leafletProxy(mapId = "map",
data = geocode(temp_loc, output = "latlon"),
session = session) %>%
addMarkers(~lon, ~lat, label = htmlEscape(isolate(input$name)),
labelOptions = labelOptions(noHide = T, textsize = "15px")),
# THIS IS WHERE I WANT TO SAVE THIS USER's DATA TO 'GLOBAL' DATA!
FULL_DATA <- rbind( FULL_DATA, c(name, temp_loc["lon"], temp_loc["lat"])})
}
I'm open to any kind of solution or a simple idea or suggestion!
Thanks in advance!