Reuse an existing Shiny Bookmark folder on server with new state input.rds and values.rds



Hello helpful Shiny friends,

I have users who embed Shiny Bookmarks links in their web pages. Sometimes the bookmark they've made needs an edit. I want override the newly created state$dir variable with the original link's directory. I know I can overwrite the input.rds and values.rds with some custom code but I'd like to take advantage of the machinery already built in the bookmark functions to compose those config files properly. Included is altered example from Shiny site. I've added code to the onBookmark() where I'd like to be able to make the change. Thanks in advance for any time you spend on this question.

[1] ‘1.1.0’

options(shiny.fullstacktrace = TRUE)
options(shiny.trace = TRUE)

ui <- function(request) {
      sliderInput("n", "Value to add", min = 0, max = 100, value = 50),
      actionButton("add", "Add"), br(), br(),
      h4("Sum of all previous slider values:", textOutput("sum"))

server <- function(input, output, session) {
  vals <- reactiveValues(sum = 0)
  #### Save extra values in state$values when we bookmark
    function(state) {
    print (session$dir)
    dir_root <- '/user/'
    dir <- '67acc0cf129049c9'
    session$dir <- paste0(dir_root,dir)
  #### Read values from state$values when we restore

onRestore(function(state) {
  vals$sum <- state$values$currentSum

#### Exclude the add button from bookmarking

observeEvent(input$add, {
  vals$sum <- vals$sum + input$n
output$sum <- renderText({

shinyApp(ui, server, enableBookmarking = "server")
> version
platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
major          3                           
minor          3.2                         
year           2016                        
month          10                          
day            31                          
svn rev        71607                       
language       R                           
version.string R version 3.3.2 (2016-10-31)
nickname       Sincere Pumpkin Patch