Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improves datanames error message (#1297)
Part of #1253 ### Changes description - `check_modules_datanames` returns a string and HTML generator for: - **string**: to be used with logger - **HTML**: function to be used in teal UI - Message is generated in the same way. This adds complexity, but is consistent - `c("one", "two", "three")` renders as "one, two and three" (note the comma and `and`) - In the module context it doesn't show the current module label <details> <summary>Sample app</summary> ```r options( teal.log_level = "TRACE", 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 = "reactive ADSL", ui = function(id) { ns <- NS(id) tagList( div("Some UI for transform (merge)"), actionButton(ns("btn"), "Reload data") ) }, server = function(id, data) { moduleServer(id, function(input, output, session) { eventReactive(input$btn, { data() }) }) } ), teal_transform_module( label = "Keep first 6 from IRIS", ui = function(id) { ns <- NS(id) div( span("Some UI for transform (1)"), textInput(ns("obs"), label = "Number of rows", value = 6) ) }, server = function(id, data) { moduleServer(id, function(input, output, session) { reactive({ req(data()) obs <- as.numeric(input$obs) if (!is.finite(obs)) stop("NOT NUMERIC.") within(data(), iris <- head(iris, n), n = as.numeric(input$obs)) }) }) } ), teal_transform_module( label = "Keep first 6 from ADTTE", ui = function(id) div("Some UI for transform 2"), server = function(id, data) { moduleServer(id, function(input, output, session) { reactive({ req(data()) within(data(), ADTTE <- head(ADTTE)) }) }) } ) ) data <- teal_data_module( once = FALSE, ui = function(id) { ns <- NS(id) tagList( numericInput(ns("obs"), "Number of observations to show", 1000), actionButton(ns("submit"), label = "Submit") ) }, server = function(id, ...) { moduleServer(id, function(input, output, session) { logger::log_trace("example_module_transform2 initializing.") eventReactive(input$submit, { data <- teal_data() |> within( { logger::log_trace("Loading data") ADSL <- head(teal.data::rADSL, n = n) ADTTE <- teal.data::rADTTE iris <- iris CO2 <- CO2 factors <- names(Filter(isTRUE, vapply(CO2, is.factor, logical(1L)))) CO2[factors] <- lapply(CO2[factors], as.character) }, n = as.numeric(input$obs) ) join_keys(data) <- default_cdisc_join_keys[c("ADSL", "ADTTE")] teal.data::datanames(data) <- c("ADSL", "ADTTE", "iris", "CO2") data }) }) } ) teal::init( data = data, modules = list( example_module("mod-1", datanames = "all"), example_module("mod-2", transformers = my_transformers, datanames = c("ADSL", "ADTTE", "iris", "elo")), modules( label = "sub-modules", example_module("mod-2-sub1", transformers = my_transformers, datanames = c("ADSL", "ADTTE", "iris", "elo", "elo2")), example_module("mod-2-sub2", transformers = my_transformers, datanames = c("ADSL", "ADTTE", "iris", "elo")) ), example_module("mod-2", transformers = my_transformers[2:3]) ), filter = teal_slices( teal_slice("ADSL", "SEX"), teal_slice("ADSL", "AGE", selected = c(18L, 65L)) ) ) |> runApp() ``` </details> ![image](https://github.com/user-attachments/assets/9a6c09a6-2ce4-4c2b-b7f6-0cce7ab8670c) ![image](https://github.com/user-attachments/assets/2b4a8dd1-f7e7-44f8-80d3-9cb45dd3909b)
- Loading branch information