Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger the reactivity on input$vals when input$col is changed #208

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions R/data_extract_filter_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ data_extract_filter_srv <- function(id, datasets, filter) {
)
})

output$html_vals_container <- renderUI({
vals_options <- reactive({
req(input$col)

choices <- value_choices(
data = datasets[[filter$dataname]](),
var_choices = input$col,
Expand All @@ -73,20 +72,41 @@ data_extract_filter_srv <- function(id, datasets, filter) {
selected <- if (!is.null(filter$selected)) {
filter$selected
} else if (filter$multiple) {
choices
restoreInput(ns("vals"), choices)
} else {
choices[1L]
restoreInput(ns("vals"), choices[1L])
}
vedhav marked this conversation as resolved.
Show resolved Hide resolved
list(choices = choices, selected = selected)
})

output$html_vals_container <- renderUI({
teal.widgets::optionalSelectInput(
inputId = ns("vals"),
label = filter$label,
choices = choices,
selected = selected,
choices = vals_options()$choices,
selected = vals_options()$selected,
multiple = filter$multiple,
fixed = filter$fixed
)
})

# Since we want the input$vals to depend on input$col for downstream calculations,
# we trigger reactivity by reassigning them. Otherwise, when input$col is changed without
# a change in input$val, the downstream computations will not be triggered.
observeEvent(input$col, {
teal.widgets::updateOptionalSelectInput(
session = session,
inputId = "vals",
choices = "",
selected = ""
)
teal.widgets::updateOptionalSelectInput(
session = session,
inputId = "vals",
choices = vals_options()$choices,
selected = vals_options()$selected
)
})
}
)
}
Expand Down