shinyWidgets
shinyWidgets copied to clipboard
[Feature request] Make selectizeGroup compatible with bookmarks
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")
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")
OK, I dont know why, but it works if you replace all selectizeInput
and updateSelectizeInput
in the module with selectInput
and updateSelectInput
.
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?
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!
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...