bookmarking shiny app results in incorrect url

I'm trying to use bookmarks to be able to save the input of my app, I'm using enableBookmarking(store = "url").
I also want to record a couple of values, the tab they are in and the time when the state was saved.

There is a nice example on how to do this on ?onBookmark, but when I use the same system for my app, I get different url and it cannot be restored.
Here they are after pasting them to the browser and copying them again:

My apps : https://url?_inputs_&...&_values_=&time=%222022-08-05%2008:00:27%22
Example : https://url?_inputs_&...&_values_&time=%222022-08-05%2008%3A01%3A22%22

Notice that &_values_&time in the example becomes &_values_=&time in my app.
Also the date in the example is %222022-08-05%2008%3A01%3A22%22 while in my app %222022-08-05%2008:00:27%22 has the colons while in the example this is escaped to %3A.

The input works well, if I don't add anything on values, but if I do it cannot be parsed and I get this error:

Error in RestoreContext initialization: Failed to parse URL parameter "_values_"

This differences prevent restoring the app to the desired state. I'm using the same browser (Chromium Version 103.0.5060.134 (Official Build) snap (64-bit)) for running and accessing both shiny apps (Shiny version 1.7.1).
What I am doing wrong or how can I work around this?

In case it is needed, I am using Shiny Server Open source v1.5.17.973 on our own (Ubuntu) server.

Last, the relevant code for bookmarking:

# on server.R
server <- function(input, output, session) { 
  ....
  # Bookmark/Restore ####
  vals <- reactiveValues(savedTime = NULL)
  onBookmark(function(state) {
    time <- as.character(Sys.time())
    cat("Last saved at", time, "\n")
    vals$savedTime <- time
    # state is a mutable reference object, and we can add arbitrary values
    # to it.
    state$values$time <- time
  })

  onRestored(function(state) {
    cat("Restoring from state bookmarked at", state$values$time, "\n")
  })
  ....
}

Edit: I checked and it is the browser which adds the _value_=.
Copied:https://url?_inputs_&color_by=%22week%22&split=%22IBD%22&statistics=%22no%22&show_legend=%22no%22&tabs=%22Summary%22&sliderh_together=400&sliderw_together=350&y_axis=%22MIR1302-2HG%22&text_size=12&x_axis=%22week%22&_values_&time=%22ha%22
Once I press enter: https://url?_inputs_&color_by=%22week%22&split=%22IBD%22&statistics=%22no%22&show_legend=%22no%22&tabs=%22Summary%22&sliderh_together=400&sliderw_together=350&y_axis=%22MIR1302-2HG%22&text_size=12&x_axis=%22week%22&_values_=&time=%22ha%22.

I have disable all my extensions and tested it with Firefox and Chromium, interestingly if the connection is refused, the url is not updated. It might be a thing of rstudio-server and not shiny...

This works just fine locally:

library(shiny)

ui <- function(request) {
  fluidPage(
    bookmarkButton()
  )
}

server <- function(input, output, session) { 
  # Bookmark/Restore ####
  onBookmark(function(state) {
    time <- as.character(Sys.time())
    cat("Last saved at", time, "\n")
    # state is a mutable reference object, and we can add arbitrary values
    # to it.
    state$values$time <- time
  })
  
  onRestored(function(state) {
    cat("Restoring from state bookmarked at", state$values$time, "\n")
  })
}

shinyApp(ui, server, enableBookmarking = "url")

Thanks for checking. Indeed, and other similar apps work too. I will try to create a reprex, but still on the server my url gets modified...

This might be related:

Also please see:

The first link might be related, I'll investigate. I also thought it could be related to this other issue in shiny-server: Shiny Server Pro: `updateQueryString()` serious bug, URL path gets modified instead of only query string · Issue #437 · rstudio/shiny-server · GitHub
There isn't any other app adding parameters (AFAIK).

Many thanks

PS: The example you posted works fine too in the server... :sweat:

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.