-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating choices using updateSelect(ize)Input causes selection to be cleared #4118
Comments
Here's a modified version of the example app that shows the behavior of Example applibrary(shiny)
library(bslib)
# List of days of the week
days_of_week <- c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
ui <- page_fluid(
card(
layout_columns(
selectizeInput("day_select_mult", "Select a day", choices = days_of_week[1:5], selected = "Monday", multiple = TRUE),
selectInput("day_select_single", "Select a day", choices = days_of_week[1:5], selected = "Monday", multiple = FALSE)
),
input_switch("include_weekends", "Include Weekends"),
textOutput("selected_day")
)
)
server <- function(input, output, session) {
output$selected_day <- renderText({
paste("You selected:", paste(input$day_select, collapse = ", "))
})
observeEvent(input$include_weekends, {
new_choices <- if (input$include_weekends) days_of_week else days_of_week[1:5]
updateSelectizeInput(
session,
"day_select_mult",
choices = new_choices
# selected = intersect(input$day_select, new_choices)
)
updateSelectizeInput(
session,
"day_select_single",
choices = new_choices
)
}, ignoreInit = TRUE)
}
shinyApp(ui, server) |
This bug has been around for a bit, I can reproduce with at least Shiny 1.7.0 (Sept 2021). (Note it might go further back, I just picked a sufficiently old version to make sure this isn't related to work I did earlier this year.) |
In my experience the following idiom on the R side is quite common
perhaps it points the way to a solution ? |
With
selectizeInput(multiple = TRUE)
, callingupdateSelectizeInput(session, "id", choices = ...)
causes the selection to reset, even if the currently selected item is in the set of choices. (Doesn't happen withoutmultiple = TRUE
.)Same with
selectInput
/updateSelectInput
, with bothselectize=TRUE
andFALSE
.System details
shinylive
Example application or steps to reproduce the problem
https://shinylive.io/r/editor/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKAZwAtaJWAlAB0IdJiw71OY4RBEBiAAQAZWp1KKiAM0UATKK06adpbnEUB3OHADWI-YYD62x1duKAPAFpFBdkLAAWRIHANxFAIAVAFc4TlC8CLAAdThdCDiE8KjuaMZ4gzCkgDFGWiykgGUoUjyKgMroiATZEWjaTx9UKABzOEctanbdfwhFXxYRkXHxzjhqOAJSWgAvOABJCFRo0n8wB0c5haWihvnFjSg9QsSCbiJaAjjFAF5rpxc3G3Cji7TXpLBZo3cIwaLUZaoBYAyJYACqAFEBLhpjMoEtaCQAEI7UgkPbRVD6ciOeikOSJAJwok1cwAYXujziAWRqPG5AAHqQAPI7ba7AK-JZpRwtVGyVoQOaMABucEYnUUWiaGPxfH54SIfJ2PzinExEAEihAqK1pH5ABIheRdKKDIrGBRdPLInAuewTWMZt11HA9gBNLWKa1pRBFdU7C0Ha2ycYAX1jES9RCk8rlCLlZHYEdIFsJxP6ZIg4U9M0U+dplXOGLWm35XD1Buy+wMh2rpCKdweTyMbwcnGcWlc1m+wfb-zefgEiYTIjjIhEPD4rAAguh2O1dbL5bIwHGALpAA
Click the button, see that the selection is reset.
The text was updated successfully, but these errors were encountered: