shinyWidgets icon indicating copy to clipboard operation
shinyWidgets copied to clipboard

[Feature request] Make selectizeGroup compatible with bookmarks

Open stephLH opened this issue 4 years ago • 5 comments

Hello Victor, In one of my projects, I try to allow bookmarking in an app using selectizeGroup input. But unfortunetaly, it seems that this widget does support restoring bookmarks yet ?

Below is a reproducable example with server bookmarking. Values are well stored in the rds, but the problem might com from restoring values ? Maybe like a updateSelectizeGroup function call could do the trick within onRestore(function(state)){} ?

library(shiny)
library(shinyWidgets)

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

ui <- function(request) {
  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:"),
              model = list(inputId = "model", title = "Model:"),
              trans = list(inputId = "trans", title = "Trans:"),
              class = list(inputId = "class", title = "Class:")
            )
          ), status = "primary"
        ),
        DT::dataTableOutput(outputId = "table"),
        bookmarkButton()
      )
    )
  )
}

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

shinyApp(ui, server, enableBookmarking = "server")

stephLH avatar May 01 '20 12:05 stephLH

After more self-documentation on bookmarks, I have tried several things espacially onRestored which should solve my issue. I dont understand why my actionButton is functionnal while onRestored is not, thought it should be executed at the end of session startup.

library(shiny)
library(shinyWidgets)

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

ui <- function(request) {
  fluidPage(
    fluidRow(
      column(
        width = 10, offset = 1,
        bookmarkButton(),
        actionButton("restore", "Restore"),
        tags$h3("Filter data with selectize group"),
        panel(
          selectizeGroupUI(
            id = "my-filters",
            params = list(
              manufacturer = list(inputId = "manufacturer", title = "Manufacturer:"),
              model = list(inputId = "model", title = "Model:"),
              trans = list(inputId = "trans", title = "Trans:"),
              class = list(inputId = "class", title = "Class:")
            )
          ), 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")
  )
  
  output$table <- DT::renderDataTable(res_mod())
  
  # Doesn't work
  onRestored(function(state) {
    
    updateSelectizeInput(
      session,
      inputId = "my-filters-manufacturer",
      selected = "audi"
    )
    
  })
  
  # Works
  observeEvent(input$restore, {
    
    updateSelectizeInput(
      session,
      inputId = "my-filters-manufacturer",
      selected = "audi"
    )
    
  })

}

shinyApp(ui, server, enableBookmarking = "server")

stephLH avatar May 03 '20 10:05 stephLH

OK, I dont know why, but it works if you replace all selectizeInput and updateSelectizeInput in the module with selectInput and updateSelectInput.

stephLH avatar May 03 '20 11:05 stephLH

Hi steph! I am struggling with the same problem. If i understand correctly, after you changed updateSelectizeInput to updateSelectInput the bookmarks in the selectizeGroup restored? I tried to do the same thing but doesn't work for me. Maybe I misunderstood something?

DomKiss avatar Jan 29 '21 23:01 DomKiss

Hi Steph, I am having the same doubt and issue of DomKiss, if I just replace updateSelectizeInput with updateSelectInput in the code you provided is still not working. Could you tell us how you fixed it? Thank you!

lucalamoni avatar Sep 24 '21 09:09 lucalamoni

Sorry guys, I changed my job position last year and I am no longer involved in this project... (neither shiny at the moment) So unfortunately, I cannot reproduce the code and help you...

stephLH avatar Sep 25 '21 10:09 stephLH