You can use shiny's bookmarking along with a database to store arbitrary data just fine:
library(RSQLite)
library(shiny)
con <- dbConnect(RSQLite::SQLite(), "test.db")
onStop(function(){dbDisconnect(con)})
ui <- function(req) {
fluidPage(
textInput("txt1", "Input text"),
textInput("txt2", "Input text"),
bookmarkButton()
)
}
server <- function(input, output, session) {
setBookmarkExclude(c("txt1", "txt2"))
onBookmark(function(state) {
dbDF <- data.frame(dir = state$dir, txt1 = paste("We just got restored...", input$txt1), txt2 = paste("...from a database!", input$txt2), stringsAsFactors = FALSE)
if(!"dbDF" %in% dbListTables(con)){
dbWriteTable(con, "dbDF", dbDF)
} else {
dbAppendTable(con, "dbDF", dbDF)
}
})
onRestored(function(state) {
resDF <- dbGetQuery(con, sprintf("Select txt1, txt2 FROM dbDF WHERE dir = '%s'", state$dir))
updateTextInput(session, "txt1", value = resDF$txt1)
updateTextInput(session, "txt2", value = resDF$txt2)
})
}
enableBookmarking("server")
shinyApp(ui, server)
Please see this.