Changing bookmark state directory when saving to disk

Is there any way to overwrite the default state directory or any reason why the option is not available?

There is are undocumented ways. The more 'official' way is through a shiny-server config setting, but it looks as though your only interested in running Shiny locally (shiny-server only runs on Linux). In that case, you can set the (undocumented) save.interface option. When Shiny runs locally, it defaults to this function, but you can override it:

my_save_interface <- function(id, callback) {
  path <- switch(
    Sys.info()[['sysname']],
    Windows = gsub("\\\\", "/", file.path(Sys.getenv("USERPROFILE"),"Desktop",fsep="/")),
    Darwin = "~/Desktop",
    getShinyOption("appDir", default = getwd())
  )
  stateDir <- file.path(path, "shiny_bookmarks", id)
  if (!shiny:::dirExists(stateDir))
    dir.create(stateDir, recursive = TRUE)
  callback(stateDir)
}

shinyOptions(save.interface = my_save_interface)

Keep in mind that this option is not documented because it's easy to shoot yourself in the foot. By using something other than the application directory for the bookmarking state, you're assuming a lot about the user's environment. Even if you have the setup and permissions, you could be overwriting files that shouldn't overwritten, and you lose the ability easily tell what state folder belongs to which app.

3 Likes