shinyWidgets icon indicating copy to clipboard operation
shinyWidgets copied to clipboard

selectizeGroupUI overwrites user defined choices and selected parameter

Open ismirsehregal opened this issue 3 years ago • 2 comments

Coming from here or here.

When passing choices or selected parameters to selectizeGroupUI's params they are overwritten on startup.

This might make sense for the choices as they are defined by the data.frame but a pre-selection should be possible.

library(shiny)
library(shinyWidgets)

data("mpg", package = "ggplot2")

ui <- fluidPage(
  fluidRow(
    column(
      width = 10, offset = 1,
      tags$h3("Filter data with selectize group"),
      panel(
        selectizeGroupUI(
          id = "my-filters",
          params = list(
            manufacturer = list(inputId = "manufacturer", title = "Manufacturer:", choices = c("audi", "dodge"), selected = "dodge", multiple = FALSE),
            model = list(inputId = "model", title = "Model:"),
            trans = list(inputId = "trans", title = "Trans:"),
            class = list(inputId = "class", title = "Class:")
          ),
          inline = TRUE
        ), status = "primary"
      ),
      DT::dataTableOutput(outputId = "table")
    )
  )
)

server <- function(input, output, session) {
  res_mod <- callModule(
    module = selectizeGroupServer,
    id = "my-filters",
    data = mpg,
    vars = c("manufacturer", "model", "trans", "class"),
    inline = TRUE
  )
  output$table <- DT::renderDataTable({res_mod()})
}

shinyApp(ui, server)

In general I think it would make sense to allow passing all of selectizeInput's parameters via params.

ismirsehregal avatar Dec 07 '22 08:12 ismirsehregal

I will deprecate this module in next release, see https://dreamrs.github.io/datamods/reference/select-group.html for a replacement, but it should have the same issue.

Victor

pvictor avatar Dec 07 '22 09:12 pvictor

Hi Victor, last time I made a PR you already mentioned that you were thinking about moving the function. Thanks for the Info!

ismirsehregal avatar Dec 07 '22 09:12 ismirsehregal