dreamRs / datamods

Shiny modules to import and manipulate data into an application or addin
https://dreamrs.github.io/datamods/
GNU General Public License v3.0
138 stars 35 forks source link

select all values (select_group_ui) #95

Closed RKonstantinR closed 7 months ago

RKonstantinR commented 7 months ago

Thanks for the great package!

It is possible to add a checkbox button to select all values ​​as is implemented in the Virtual Select?

изображение

Adding an argument multiple = TRUE doesn't help

select_group_ui(
                    id = "my-filters",
                    params = list(
                        list(inputId = "Manufacturer", label = "Manufacturer:"),
                        list(inputId = "Type", label = "Type:"),
                        list(inputId = "AirBags", label = "AirBags:"),
                        list(inputId = "DriveTrain", label = "DriveTrain:")
                    ),
                    vs_args = list(multiple = TRUE)
                )

изображение

pvictor commented 7 months ago

Selecting all values is the same as selecting none, what is the use case here ? There's some options hard coded here https://github.com/dreamRs/datamods/blob/c6da75e8d972febde3b5427d9d4aac074f1aa369/R/select-group.R#L68, maybe I can make them optional.

RKonstantinR commented 7 months ago

In some cases, it is faster to select all values and exclude some than to select all the values of interest one by one. For example, to filter 18 out of 20 values, you need to either select the value of interest 18 times or select all and exclude 2. 3 clicks against 18.

pvictor commented 7 months ago

Ok that's a good point ! If you re-intall from GitHub you can now set disableSelectAll = FALSE to let user te ability to select all, e.g. :

library(shiny)
library(datamods)
library(shinyWidgets)

ui <- fluidPage(
  # theme = bslib::bs_theme(version = 5L),
  fluidRow(
    column(
      width = 10, offset = 1,
      tags$h3("Filter data with select group module"),
      shinyWidgets::panel(
        select_group_ui(
          id = "my-filters",
          params = list(
            list(inputId = "Manufacturer", label = "Manufacturer:"),
            list(inputId = "Type", label = "Type:"),
            list(inputId = "AirBags", label = "AirBags:"),
            list(inputId = "DriveTrain", label = "DriveTrain:")
          ),
          vs_args = list(
            disableSelectAll = FALSE,
            showValueAsTags = FALSE,
            alwaysShowSelectedOptionsCount = TRUE
          )
        ),
        status = "primary"
      ),
      reactable::reactableOutput(outputId = "table"),
      tags$b("Inputs values:"),
      verbatimTextOutput("inputs")
    )
  )
)

server <- function(input, output, session) {
  res_mod <- select_group_server(
    id = "my-filters",
    data = reactive(MASS::Cars93),
    vars = reactive(c("Manufacturer", "Type", "AirBags", "DriveTrain"))
  )

  output$table <- reactable::renderReactable({
    reactable::reactable(res_mod())
  })

  output$inputs <- renderPrint({
    attr(res_mod(), "inputs")
  })
}

if (interactive())
  shinyApp(ui, server)
RKonstantinR commented 7 months ago

Everything works great. Thanks for the quick feedback!