mirror of
https://github.com/rstudio/shiny.git
synced 2026-02-07 05:04:58 -05:00
31 lines
1021 B
R
31 lines
1021 B
R
# Function wrappers for saving and restoring state to/from disk when running
|
|
# Shiny locally.
|
|
#
|
|
# These functions provide a directory to the callback function.
|
|
#
|
|
# @param id A session ID to save.
|
|
# @param callback A callback function that saves state to or restores state from
|
|
# a directory. It must take one argument, \code{stateDir}, which is a
|
|
# directory to which it writes/reads.
|
|
|
|
saveInterfaceLocal <- function(id, callback) {
|
|
# Try to save in app directory, or, if that's not available, in the current
|
|
# directory.
|
|
appDir <- getShinyOption("appConfig")$appDir %OR% getwd()
|
|
|
|
stateDir <- file.path(appDir, "shiny_bookmarks", id)
|
|
if (!dirExists(stateDir))
|
|
dir.create(stateDir, recursive = TRUE)
|
|
|
|
callback(stateDir)
|
|
}
|
|
|
|
loadInterfaceLocal <- function(id, callback) {
|
|
# Try to save in app directory, or, if that's not available, in the current
|
|
# directory.
|
|
appDir <- getShinyOption("appConfig")$appDir %OR% getwd()
|
|
|
|
stateDir <- file.path(appDir, "shiny_bookmarks", id)
|
|
callback(stateDir)
|
|
}
|