insightsengineering / teal

Exploratory Web Apps for Analyzing Clinical Trial Data
https://insightsengineering.github.io/teal/
Other
171 stars 34 forks source link

Fix #1130

Closed gogonzo closed 5 months ago

gogonzo commented 6 months ago

I've investigated the problem of not-restoring module inputs and updateInput is not a biggest problem there. Fundamental problem is that onRestored is triggered before teal_module(s) is called. It means that onRestore has (yet) no values to update. Root of the problem lays here. This commit seems to solve this issue:

example app ```r options(teal.log_level = "TRACE", teal.show_js_log = TRUE, teal.bs_theme = bslib::bs_theme(version = 3)) logger::log_warnings() pkgload::load_all("teal") tdata <- teal_data() |> within({ set.seed(1) library(scda) library(MultiAssayExperiment) library(stats) ts_example <- ts(matrix(rnorm(300), 100, 3), start = c(1961, 1), frequency = 12) data(miniACC, envir = environment()) a_matrix <- matrix(rnorm(100), ncol = 5, dimnames = list(rownames = NULL, colnames = c("a", "b", "c", "d", "e"))) a_vector <- "elo" ADSL <- synthetic_cdisc_data("latest")$adsl attr(ADSL, "label") <- "ADSL dataset" ADSL$categorical <- sample(letters[1:3], size = nrow(ADSL), replace = TRUE, prob = c(.1, .3, .6)) ADTTE <- synthetic_cdisc_data("latest")$adtte ADRS <- synthetic_cdisc_data("latest")$adrs }) datanames(tdata) <- c("ADSL", "ADTTE", "ADRS", "miniACC", "a_vector", "a_matrix", "ts_example") join_keys(tdata) <- default_cdisc_join_keys[c("ADSL", "ADTTE", "ADRS")] data <- teal_data_module( ui = function(id) { ns <- NS(id) div(actionButton(ns("btn"), "Click me")) }, server = function(id) { moduleServer(id, function(input, output, session) { eventReactive(input$btn, tdata) }) } ) app <- init( data = tdata, modules = modules( modules( label = "tab1", example_module("funny"), example_module("funny", datanames = "miniACC"), example_module("funny2", datanames = c("ADTTE", "ADTTE")), # will limit datanames to ADTTE and ADSL (parent), teal.modules.general::tm_data_table() ) ) ) runApp(app) ```