Skip to content
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

Select one element per group did not work after updatePickerInput ('max-options-group' = 1) #670

Closed
jonasmuench opened this issue Feb 26, 2024 · 3 comments

Comments

@jonasmuench
Copy link

If I update a picker input with updatePickerInput, I can select more than one element per group although I have previously restricted it with the option 'max-options-group' = 1. Is this a bug or am I missing something?

library(shiny)
library(shinyWidgets) # 0.8.1

ui <- fluidPage(
  
  # Select ohne Element per Group
  pickerInput(inputId = "test",
                            label = "Picker",
                            choices = list("Group1" = list("A" = "A1", "B" = "B1"),
                                           "Group2" = list("A" = "A2", "B" = "B2", "C" = "C2"),
                                           "Group3" = list("A" = "A3", "B" = "B3", "C" = "C3")),
                            selected = c("A1", "B2", "C3"),
                            multiple = TRUE,
                            options = list(`max-options-group` = 1L,
                                           title = "Select one per group",
                                           `selected-text-format` = "count > 1",
                                           `count-selected-text` = "{0} Groups")
                            
  ),
  actionButton(inputId = "update_test",
               label = "Update the picker"
  ),
  br(),
  verbatimTextOutput(outputId = "res")
)

server <- function(input, output, session) {
  
  observeEvent(input$update_test, {
    updatePickerInput(session = session,
                                    inputId = "test",
                                    label = "Updated picker",
                                    choices = list("Group1" = list("A" = "A1", "B" = "B1"),
                                                   "Group2" = list("A" = "A2", "B" = "B2", "C" = "C2"),
                                                   "Group3" = list("A" = "A3", "B" = "B3", "C" = "C3")),
                                    selected = c("A1", "B2", "C3")
    )
  })
  
  output$res <- renderPrint({
    input$test
  })
}

shinyApp(ui, server)

After update:
image

@jonasmuench jonasmuench changed the title Select one element per Group did not work after updatePickerInput Select one element per group did not work after updatePickerInput ('max-options-group' = 1) Feb 26, 2024
@pvictor
Copy link
Member

pvictor commented Feb 27, 2024

Thanks for reporting this, it's fixed if you re-install from GitHub, but you have to repeat the option in updatePickerInput(), e.g. :

updatePickerInput(
  session = session,
  inputId = "test",
  label = "Updated picker",
  choices = list(
    "Group1" = list("A" = "A1", "B" = "B1"),
    "Group2" = list("A" = "A2", "B" = "B2", "C" = "C2"),
    "Group3" = list("A" = "A3", "B" = "B3", "C" = "C3")
  ),
  selected = c("A1", "B2", "C3"),
  options = list(`max-options-group` = 1L)
)

@jonasmuench
Copy link
Author

Thanks, when will there be a new version on CRAN?

@pvictor
Copy link
Member

pvictor commented Mar 1, 2024

On CRAN now ;)

@pvictor pvictor closed this as completed Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants