File: bookmark-state-local.R

package info (click to toggle)
r-cran-shiny 1.5.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,224 kB
  • sloc: javascript: 17,081; sh: 28; makefile: 21
file content (28 lines) | stat: -rw-r--r-- 895 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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
  appDir <- getShinyOption("appDir", default = getwd())

  stateDir <- file.path(appDir, "shiny_bookmarks", id)
  if (!dirExists(stateDir))
    dir.create(stateDir, recursive = TRUE)

  callback(stateDir)
}

loadInterfaceLocal <- function(id, callback) {
  # Try to load from app directory
  appDir <- getShinyOption("appDir", default = getwd())

  stateDir <- file.path(appDir, "shiny_bookmarks", id)
  callback(stateDir)
}