lundi 7 mai 2018

r shiny hide/show all checked checkboxes

I would like to simply hide or show all checked checkboxes in R shiny the following code can be used as a reference :

ui <- shinyUI({
  library(shiny)
  library(shinyjs)

  shinyUI(fluidPage(

    shinyjs::useShinyjs(),

    actionButton(inputId = "fishButton",  label = "Fish"),
    checkboxInput(inputId = "hide_show_checked", label = "Hide/Show all checked checkbozes"),
    hidden(
      checkboxGroupInput(inputId = "Check1",
                         label   = h4("Fish:"), 
                         choices = c("Bass", "Shark", "Tuna"))
    )
  ))
})


serv <- shinyServer({
  library(shiny)
  library(shinyjs)

  shinyServer(function(input, output) {
    observeEvent(input$fishButton, {
      toggle("Check1")
    })
  })
})

shinyApp(ui,serv)

I am sure I would need to add an observe event in the server part, but I am tending to overthink this, by creating duplicate checkbox groups and displaying the checkbox group 1 if checked and displaying checkbox group 2 if not checked... This would result in a lot of duplication in my actual code (I have more than 1000 checkbox groups)

Thanks!!




Aucun commentaire:

Enregistrer un commentaire