Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce decorators for
tm_t_coxreg
(#1274)
Part of insightsengineering/teal#1371 <details> <summary>Example with decorator</summary> ```r load_all("../teal.code") load_all("../teal.data") load_all("../teal") load_all(".") arm_ref_comp <- list( ACTARMCD = list( ref = "ARM B", comp = c("ARM A", "ARM C") ), ARM = list( ref = "B: Placebo", comp = c("A: Drug X", "C: Combination") ) ) insert_rrow_decorator <- function(default_caption = "I am a good new row", .var_to_replace = "table") { teal_transform_module( label = "New row", ui = function(id) shiny::textInput(shiny::NS(id, "new_row"), "New row", value = default_caption), server = make_teal_transform_server( substitute({ .var_to_replace <- rtables::insert_rrow(.var_to_replace, rtables::rrow(new_row)) }, env = list(.var_to_replace = as.name(.var_to_replace))) ) ) } data <- within(teal_data(), { ADSL <- tmc_ex_adsl ADTTE <- tmc_ex_adtte }) join_keys(data) <- default_cdisc_join_keys[names(data)] ADSL <- data[["ADSL"]] ADTTE <- data[["ADTTE"]] app <- init( data = data, modules = modules( tm_t_coxreg( label = "Cox Reg.", dataname = "ADTTE", arm_var = choices_selected(c("ARM", "ARMCD", "ACTARMCD"), "ARM"), arm_ref_comp = arm_ref_comp, paramcd = choices_selected( value_choices(ADTTE, "PARAMCD", "PARAM"), "OS" ), strata_var = choices_selected( c("COUNTRY", "STRATA1", "STRATA2"), "STRATA1" ), cov_var = choices_selected( c("AGE", "BMRKR1", "BMRKR2", "REGION1"), "AGE" ), multivariate = TRUE, decorators = list(insert_rrow_decorator()) ) ) ) if (interactive()) { shinyApp(app$ui, app$server) } ## Second example library(dplyr) data <- teal_data() data <- within(data, { ADTTE <- data.frame( STUDYID = "LUNG", AVAL = c(4, 3, 1, 1, 2, 2, 3, 1, 2), CNSR = c(1, 1, 1, 0, 1, 1, 0, 0, 0), ARMCD = factor( c(0, 1, 1, 1, 1, 0, 0, 0, 0), labels = c("ARM A", "ARM B") ), SEX = factor( c(0, 0, 0, 0, 1, 1, 1, 1, 1), labels = c("F", "M") ), INST = factor(c("A", "A", "B", "B", "A", "B", "A", "B", "A")), stringsAsFactors = FALSE ) ADTTE <- rbind(ADTTE, ADTTE, ADTTE, ADTTE) ADTTE <- as_tibble(ADTTE) set.seed(1) ADTTE$INST <- sample(ADTTE$INST) ADTTE$AGE <- sample(seq(5, 75, 5), size = nrow(ADTTE), replace = TRUE) ADTTE$USUBJID <- paste("sub", 1:nrow(ADTTE), ADTTE$INST, sep = "-") ADTTE$PARAM <- ADTTE$PARAMCD <- "OS" ADSL <- subset( ADTTE, select = c("USUBJID", "STUDYID", "ARMCD", "SEX", "INST", "AGE") ) }) join_keys(data) <- default_cdisc_join_keys[names(data)] ADSL <- data[["ADSL"]] ADTTE <- data[["ADTTE"]] ## `teal` application ## ---------------- ## Note that the R code exported by `Show R Code` does not include the data ## pre-processing. You will need to create the dataset as above before ## running the exported R code. arm_ref_comp <- list(ARMCD = list(ref = "ARM A", comp = c("ARM B"))) app <- init( data = data, modules = modules( tm_t_coxreg( label = "Cox Reg.", dataname = "ADTTE", arm_var = choices_selected(c("ARMCD"), "ARMCD"), arm_ref_comp = arm_ref_comp, paramcd = choices_selected( value_choices(ADTTE, "PARAMCD", "PARAM"), "OS" ), strata_var = choices_selected(c("INST"), NULL), cov_var = choices_selected(c("SEX", "AGE"), "SEX"), multivariate = TRUE, decorators = list(insert_rrow_decorator()) ) ) ) if (interactive()) { shinyApp(app$ui, app$server) } ``` </details> --------- Signed-off-by: Lluís Revilla <[email protected]> Co-authored-by: André Veríssimo <[email protected]>
- Loading branch information