How to save data in session to global in order to achieve data sharing

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!

You need some persistent storage like a database back end that you can wrote to with new info and have every open session poll for changes.

1 Like

Hello again Hamuk, thank you for answering my question again! I guess I'll have to learn some db from scratch :desktop_computer:

for those who are going to do the similar things, I found some introduction to do this:
https://shiny.rstudio.com/articles/persistent-data-storage.html

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.