Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delays transform modules reactivity until tab is active (#1373)
# Pull Request Fixes #1303 ### Changes description - [x] Unifying function for delayed trigger of module and transformations - [x] Filter manager crash when clicked with an app that has module specific filters - [x] Fix bug detected when app is called with `teal_data_module` - One of my testing apps is failing (see below) - [x] Add tests ### Topics to discuss - **Functionality change**: this PR will delay the first module reactivity execution until data is pulled from `teal_data_module` <details> <summary>Sample app for bug</summary> ```R options( teal.log_level = "INFO", teal.show_js_log = TRUE, # teal.bs_theme = bslib::bs_theme(version = 5), shiny.bookmarkStore = "server" ) # pkgload::load_all("../teal.data") # pkgload::load_all("../teal.slice") pkgload::load_all("../teal") my_transformers <- list( teal_transform_module( label = "Keep first 6 from IRIS", ui = function(id) { ns <- NS(id) div( checkboxInput(ns("check"), label = "Toggle `head(iris)`"), ) }, server = function(id, data) { moduleServer(id, function(input, output, session) { eventReactive(input$check, { print("Check triggered") req(data()) if (input$check) { within(data(), iris <- head(iris, 6)) } else { data() } }) }) } ) ) data <- teal::teal_data_module( ui = function(id) { ns <- shiny::NS(id) shiny::tagList( shiny::tags$head( shiny::tags$style(shiny::HTML(" .teal-data-module { border: 1px solid rgba(0, 0, 0, .5); border-radius: 4px; padding: 1em; margin: .2em; } .teal-data-module .shiny-options-group { display: flex; flex-wrap: wrap; column-gap: 1em; } .teal-data-module .shiny-options-group .checkbox { margin-top: 1em; margin-bottom: 0; } ")) ), shiny::tags$h2("Data Module"), shiny::div( class = "teal-data-module", shiny::checkboxGroupInput( ns("datasets"), "Datasets", choices = c("ADSL", "ADTTE", "iris", "CO2", "miniACC"), selected = c("ADSL", "ADTTE", "iris", "CO2") ), shiny::actionButton(ns("submit"), label = "Submit") ) ) }, server = function(id, ...) { shiny::moduleServer(id, function(input, output, session) { code <- list( ADSL = expression(ADSL <- teal.data::rADSL), ADTTE = expression({ ADTTE <- teal.data::rADTTE ADTTE$CNSRL <- as.logical(ADTTE$CNSR) }), iris = expression(iris <- iris), CO2 = expression({ CO2 <- CO2 factors <- names(Filter(isTRUE, vapply(CO2, is.factor, logical(1L)))) CO2[factors] <- lapply(CO2[factors], as.character) }), miniACC = expression({ data( "miniACC", package = "MultiAssayExperiment", envir = environment(), overwrite = TRUE ) miniACC <- miniACC }) ) datasets <- reactive(input$datasets) shiny::eventReactive(input$submit, { code_to_eval <- do.call(c, code[datasets()]) data <- teal.code::eval_code(teal.data::teal_data(), code_to_eval) join_keys(data) <- default_cdisc_join_keys[datasets()] teal.data::datanames(data) <- datasets() data }) }) }, once = FALSE ) teal::init( data = data, modules = teal::modules( teal::example_module(label = "A", datanames = NULL, transformers = my_transformers), teal::example_module(label = "B", transformers = my_transformers) ), filter = teal::teal_slices( # # FilterRange teal.slice::teal_slice("ADSL", "AGE", selected = c(18L, 65L)), # # FilterExpr teal_slice( dataname = "ADSL", id = "Female adults", expr = "SEX == 'F' & AGE >= 18", title = "Female adults" ), # # FilterDatetime teal_slice( dataname = "ADTTE", varname = "ADTM", id = "Analysis DTM", selected = c("2019-03-25 07:06:18", "2020-01-22 15:03:58"), title = "Female adults" ), # # FilterDate with LSTALVDT teal_slice( dataname = "ADSL", varname = "LSTALVDT", id = "Last Alive Date", selected = c("2022-02-14", "2022-11-24"), title = "Last Alive Date" ), # FilterEmpty # FilterLogical with CNSRL teal_slice( dataname = "ADTTE", varname = "CNSRL", id = "Censored", selected = TRUE, title = "Censored" ), module_specific = FALSE, teal.slice::teal_slice("ADSL", "SEX") ), title = "yada" ) |> shiny::runApp() ``` </details> --------- Signed-off-by: André Veríssimo <[email protected]> Co-authored-by: m7pr <[email protected]> Co-authored-by: Marcin <[email protected]> Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Dawid Kałędkowski <[email protected]>
- Loading branch information