shiny.semantic icon indicating copy to clipboard operation
shiny.semantic copied to clipboard

Feature request: add a 'Select all' button in `multiple_checkbox()`

Open u9090 opened this issue 2 years ago • 1 comments

This feature could be implemented as in #378 , but this approach does not always work (in modules, renderUI, ...).

u9090 avatar Jul 22 '21 09:07 u9090

Workaround, adding a toggle or checkbox In the link: https://stackoverflow.com/c/appsilon/questions/214/219#219

library(shiny.semantic)
library(shiny)

two_list<-list(as.character(c(10,20,30,40,50,60) ) )

ui <- semanticPage(
  
  uiOutput("servicetypeUI1")
  ,shiny.semantic::toggle(input_id="allNoneInput"
                          , label = "All/None"
                          , is_marked = TRUE
                          , style = NULL)
)

server <- function(input, output, session) {
  
  observeEvent(input$allNoneInput,{
    if(input$allNoneInput ) {
      update_multiple_checkbox(session, input_id="type"
                               , selected = as.character(seq_along(
                                 two_list[[1]]) )
      )
    } else {
      update_multiple_checkbox(session, input_id="type"
                               , selected = list())
    }
    
  })
  
  output$servicetypeUI1  <- renderUI({
    tagList(
      div(
          strong("Service type")
      )
      ,multiple_checkbox(
        input_id = "type",
        label = "",
        choices = two_list[[1]],
        choices_value = as.character(seq_along(two_list[[1]]) ),
        selected      = as.character(seq_along(two_list[[1]]) )
      )
    )
  })
}
shiny::shinyApp(ui, server)

fernandoroa avatar Mar 07 '22 14:03 fernandoroa