shiny
shiny copied to clipboard
Bookmarking a frozen input throws an error
System details
Output of sessionInfo():
R version 4.3.3 (2024-02-29)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.4.1
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: America/New_York
tzcode source: internal
attached base packages:
[1] stats graphics grDevices datasets utils methods base
other attached packages:
[1] shiny_1.8.1.1
loaded via a namespace (and not attached):
[1] digest_0.6.35 later_1.3.2 R6_2.5.1 httpuv_1.6.15 fastmap_1.1.1 magrittr_2.0.3 cachem_1.0.8 memoise_2.0.1 htmltools_0.5.8.1 lifecycle_1.0.4
[11] promises_1.3.0 cli_3.6.2 xtable_1.8-4 sass_0.4.9 jquerylib_0.1.4 renv_1.0.5 compiler_4.3.3 rstudioapi_0.16.0 tools_4.3.3 bslib_0.7.0
[21] mime_0.12 Rcpp_1.0.12 jsonlite_1.8.8 rlang_1.1.3
Example application or steps to reproduce the problem
library(shiny)
# Using shiny bookmarking, freezing any input that is part of the bookmark results in an error
# but does not appear to break restoration
shinyApp(
ui = function(request) {
fluidPage(
selectizeInput("dynamic_parent", "Dynamic Parent", choices = c('mtcars', 'airquality', 'warpbreaks'), multiple = FALSE),
selectizeInput("dynamic_child", "Dynamic Child", choices = NULL, multiple = FALSE),
verbatimTextOutput("output")
)
},
server = function(input, output, session) {
# Automatically bookmark every time an input changes
observe({
reactiveValuesToList(input)
session$doBookmark()
})
# Update the query string
onBookmarked(updateQueryString)
# Dynamically created inputs must be restored
onRestored(function(state) {
updateSelectizeInput(session, "dynamic_child", selected = state$input$dynamic_child)
})
# Update the dynamic child based on the dynamic parent
observe({
if (!input$dynamic_parent == "") {
updateSelectizeInput(session, "dynamic_child", choices = names(get(input$dynamic_parent)))
freezeReactiveValue(input, "dynamic_child")
}
})
# Output
output$output <- renderText({paste0(names(reactiveValuesToList(input)),' = ',reactiveValuesToList(input), collapse = ", ")})
},
enableBookmarking = "url"
)
Describe the problem in detail
Freezing an input that is also bookmarked generates an error: "Error bookmarking state:". The bookmarking state appears to load correctly despite this error message, and it isn't clear from the bookmarking documentation that freezing an input should create an issue. While freezing is not necessary in this example application, this error is preventing me from rolling out bookmarking in a more complicated application that does require freezeReactiveValue on inputs that would also be bookmarked.