Debian Codegraph @

R/bookmark-state-local.R

raw
1 # Function wrappers for saving and restoring state to/from disk when running
2 # Shiny locally.
3 #
4 # These functions provide a directory to the callback function.
5 #
6 # @param id A session ID to save.
7 # @param callback A callback function that saves state to or restores state from
8 # a directory. It must take one argument, \code{stateDir}, which is a
9 # directory to which it writes/reads.
10
11 saveInterfaceLocal <- function(id, callback) {
12 # Try to save in app directory
13 appDir <- getShinyOption("appDir", default = getwd())
14
15 stateDir <- file.path(appDir, "shiny_bookmarks", id)
16 if (!dirExists(stateDir))
17 dir.create(stateDir, recursive = TRUE)
18
19 callback(stateDir)
20 }
21
22 loadInterfaceLocal <- function(id, callback) {
23 # Try to load from app directory
24 appDir <- getShinyOption("appDir", default = getwd())
25
26 stateDir <- file.path(appDir, "shiny_bookmarks", id)
27 callback(stateDir)
28 }