When saving bookmarks to disk, by default the state directory will be created within the app directory. I would rather specify my own state directory and tried to do this by assigning the desired path to state$dir within onBookmark but this does not seem to work - see the reproducible code below (should work on Windows and Mac).
library(shiny)
ui <- function(request) {
fluidPage(
textInput("txt", "Enter text"),
checkboxInput("caps", "Capitalize"),
verbatimTextOutput("out"),
bookmarkButton()
)
}
server <- function(input, output, session) {
output$out <- renderText({
if (input$caps)
toupper(input$txt)
else
input$txt
})
# Define default path (to be changed later)
switch(Sys.info()[['sysname']],
Windows = {path <<- gsub("\\\\", "/", file.path(Sys.getenv("USERPROFILE"),"Desktop",fsep="/"))},
Mac = {path <<- "~/Desktop"})
onBookmark(function(state) {
# Change working directory to target directory for bookmarks:
id = gsub(sprintf("%s/shiny_bookmarks/",getwd()), "", state$dir) # get unique id
state$dir = sprintf("%s/shiny_bookmarks/%s", path, id)
})
}
enableBookmarking(store="server")
shinyApp(ui, server)
Is there any way to overwrite the default state directory or any reason why the option is not available?
Many thanks in advance,
Patrick