vendredi 23 novembre 2018

Dynamic limit of Checkbox Group selection

I have a checkboxGroupInput with 4 choices (A, B, C, D).
I want to limit the allowed selection to 2 options.

The user is allowed to select a 3rd option.
But in that case only the new (3rd) and last (2nd) options that were selected should stay checked.

For example, if a user selects B, then D, and then A -
the outcome should be only D and A checked.

I'm trying to implement this logic in JS, since it doesn't work properly in R/Shiny.
The main reason is that updating the input doesn't occur immediately.
(it is delayed by other invalidations in my original Shiny app, that take quite some time)

Minimal example:

library(shiny)

shinyApp(
  ui = fluidPage(
    tags$script(
      "JS code here..."
    ),

    checkboxGroupInput(
      inputId = "the_checkbox",
      label = "Checkbox",
      choices = c("A", "B", "C", "D")
    )
  ),

  server = function(input, output, session) {}
)




Aucun commentaire:

Enregistrer un commentaire