Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make input_switch() work with Shiny bookmarking #1165

Closed
matt-dray opened this issue Jan 14, 2025 · 2 comments · Fixed by #1166
Closed

Make input_switch() work with Shiny bookmarking #1165

matt-dray opened this issue Jan 14, 2025 · 2 comments · Fixed by #1166

Comments

@matt-dray
Copy link

matt-dray commented Jan 14, 2025

Could input_switch() be made to work with Shiny bookmarking? This would allow users to 'save' the state of the component in the app, which is the normal behaviour for Shiny's own components. Note that the same behaviour is true of input_dark_mode() as well.

Here's a reprex with the input_switch component, as well as shiny::checkboxInput() for comparison:

library(shiny)
library(bslib)

ui <- function() {
  page_fluid(
    input_switch(id = "inputswitch", label = "Switch"),
    verbatimTextOutput("inputswitch_value"),
    checkboxInput(inputId = "checkbox", label = "Checkbox"),
    verbatimTextOutput("checkbox_value"),
    bookmarkButton()
  )
}

server <- function(input, output) {
  output$inputswitch_value <- renderText({input$inputswitch})
  output$checkbox_value <- renderText({input$checkbox})
}

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

Both components are off by default. If you turn them both on and then click the bookmark button, the URL will be appended with ?_inputs_&inputswitch=true&checkbox=true as expected.

But when you visit that URL, the input switch is still off, whereas the checkbox's state has been respected:

A demo Shiny app with a toggleable switch set to off and a checkbox set to on. Verbatim text displays FALSE and TRUE under the components, respectively. There is a button with the word 'bookmark' on it. Red circles have been added to highlight that the URL contains a string to say that the switch should be set to its 'TRUE' state, but the switch itself is actually off.

I couldn't find another issue or PR that matched this one. I couldn't see a reference in the docs to bookmarking. I see that input_switch()'s lifecycle stage 'experimental', so perhaps this functionality isn't planned until the component exits this phase.

@gadenbuie
Copy link
Member

Thanks for the reminder! It was just an oversight on our part. It'll be fixed in the dev version of bslib shortly.

Copy link

This issue has been automatically locked. If you have found a related problem, please open a new issue (with a reproducible example or feature request) and link to this issue.
🙋 Need help? Connect with us on Discord or Posit Community.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2025
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants