Skip to content

Commit

Permalink
fix initialization/restoration of filter vals/vars
Browse files Browse the repository at this point in the history
  • Loading branch information
gogonzo committed Mar 22, 2024
1 parent 05a12b7 commit 6d150fd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions R/data_extract_filter_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ data_extract_filter_srv <- function(id, datasets, filter) {
ns <- session$ns

output$col_container <- renderUI({
logger::log_trace("data_extract_filter_srv@1 setting up filter col input")
teal.widgets::optionalSelectInput(
inputId = ns("col"),
label = filter$vars_label,
Expand All @@ -61,31 +62,32 @@ data_extract_filter_srv <- function(id, datasets, filter) {
)
})

is_init <- reactiveVal(TRUE)
vals_options <- reactive({
req(input$col)
choices <- value_choices(
data = datasets[[filter$dataname]](),
var_choices = input$col,
var_label = if (isTRUE(input$col == attr(filter$choices, "var_choices"))) attr(filter$choices, "var_label")
)

selected <- if (!is.null(filter$selected)) {
filter$selected
selected <- if (shiny::isolate(is_init())) {
shiny::isolate(is_init(FALSE))
restoreInput(ns("vals"), filter$selected)
} else if (filter$multiple) {
choices
} else {
choices[1L]
}
selected <- restoreInput(ns("vals"), selected)
list(choices = choices, selected = selected)
})

output$vals_container <- renderUI({
logger::log_trace("data_extract_filter_srv@2 updating filter vals")
teal.widgets::optionalSelectInput(
inputId = ns("vals"),
label = filter$label,
choices = vals_options()$choices,
selected = isolate(vals_options()$selected),
selected = vals_options()$selected,
multiple = filter$multiple,
fixed = filter$fixed
)
Expand Down

0 comments on commit 6d150fd

Please sign in to comment.