insightsengineering / teal

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

1226 make new `*_data_summary` #1257

Open m7pr opened 6 days ago

m7pr commented 6 days ago

WIP Closes #1226

TODO:

Testing with below code ```r options( teal.log_level = "TRACE", teal.show_js_log = TRUE, # teal.bs_theme = bslib::bs_theme(version = 5), shiny.bookmarkStore = "server" ) library(scda) pkgload::load_all(".") data <- teal_data_module( ui = function(id) { ns <- NS(id) tagList( textInput(ns("username"), label = "Username"), passwordInput(ns("password"), label = "Password"), actionButton(ns("submit"), label = "Submit") ) }, server = function(id, ...) { moduleServer(id, function(input, output, session) { eventReactive(input$submit, { data <- teal_data() |> within( { logger::log_trace("Loading data") ADSL <- scda::synthetic_cdisc_data("latest")$adsl ADTTE <- scda::synthetic_cdisc_data("latest")$adtte iris <- iris library(MultiAssayExperiment) data("miniACC", package = "MultiAssayExperiment", envir = environment()) CO2 <- CO2 factors <- names(Filter(isTRUE, vapply(CO2, is.factor, logical(1L)))) CO2[factors] <- lapply(CO2[factors], as.character) }, username = input$username, password = input$password ) join_keys(data) <- default_cdisc_join_keys[c("ADSL", "ADTTE")] data }) }) } ) # data <- teal_data() |> # within({ # ADSL <- scda::synthetic_cdisc_data("latest")$adsl # ADTTE <- scda::synthetic_cdisc_data("latest")$adtte # iris <- iris # # CO2 <- datasets::CO2 # factors <- names(Filter(isTRUE, vapply(CO2, is.factor, logical(1L)))) # CO2[factors] <- lapply(CO2[factors], as.character) # }) # join_keys(data) <- default_cdisc_join_keys[c("ADSL", "ADTTE")] # datanames(data) <- c("ADSL", "ADTTE", "iris", "CO2") app <- teal::init( data = data, modules = list( teal.modules.general::tm_data_table("Data Table"), example_module("Example Module", datanames = "ADTTE"), example_module("Example Module (iris only)", datanames = "iris"), module( ui = function(id) { ns <- NS(id) tagList( tableOutput(ns("filter_summary")) ) }, server = function(id, datasets) { moduleServer(id, function(input, output, session) { output$filter_summary <- renderTable({ datasets$get_filter_overview(datanames = datasets$datanames()) }) }) } ) ), filter = teal_slices( teal_slice("ADSL", "SEX"), teal_slice("ADSL", "AGE", selected = c(18L, 65L)) # , # module_specific = TRUE, # mapping = list( # global_filters = "ADSL AGE", # `Example Module` = "ADSL SEX" # ) ) ) |> runApp() ```
m7pr commented 3 days ago

I've made it to the point where it works and produces proper counts for dataframes and MAE datasets. However, the code is still disgusting, so will make an effort now to simplify the code.

image
m7pr commented 9 hours ago

I see that counts for ADTTE for subjects are a bit different. So need to investigate once more.

image
m7pr commented 8 hours ago

Hey @gogonzo I think this is ready for the first round of the review. I didn't hide the previous data-summary as I don't know how, and was still using it for testing the counts with my new data-summary