Skip to content

Commit

Permalink
tdata to teal_data - tm_t_mult_events (#870)
Browse files Browse the repository at this point in the history
**Example App**
```

ADSL <- tmc_ex_adsl
ADCM <- tmc_ex_adcm
adcm_keys <- c("STUDYID", "USUBJID", "ASTDTM", "CMSEQ", "ATC1", "ATC2", "ATC3", "ATC4")

join_keys <- default_cdisc_join_keys[c("ADSL", "ADCM")]
join_keys["ADCM", "ADCM"] <- adcm_keys

app <- teal::init(
  data = cdisc_data(
    ADSL = ADSL,
    ADCM = ADCM,
    code = "
      ADSL <- tmc_ex_adsl
      ADCM <- tmc_ex_adcm
    ",
    join_keys = join_keys
  ),
  modules = modules(
    tm_t_mult_events(
      label = "Concomitant Medications by Medication Class and Preferred Name",
      dataname = "ADCM",
      arm_var = choices_selected(c("ARM", "ARMCD"), "ARM"),
      seq_var = choices_selected("CMSEQ", selected = "CMSEQ", fixed = TRUE),
      hlt = choices_selected(
        choices = variable_choices(ADCM, c("ATC1", "ATC2", "ATC3", "ATC4")),
        selected = c("ATC1", "ATC2", "ATC3", "ATC4")
      ),
      llt = choices_selected(
        choices = variable_choices(ADCM, c("CMDECOD")),
        selected = c("CMDECOD")
      ),
      add_total = TRUE,
      event_type = "treatment"
    )
  )
)
 shinyApp(app$ui, app$server)
```
  • Loading branch information
kartikeyakirar authored Nov 23, 2023
1 parent 83536ff commit ce191a3
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions R/tm_t_mult_events.R
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ srv_t_mult_events_byterm <- function(id,
basic_table_args) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "tdata")
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")

shiny::moduleServer(id, function(input, output, session) {
selector_list <- teal.transform::data_extract_multiple_srv(
Expand All @@ -487,23 +488,21 @@ srv_t_mult_events_byterm <- function(id,
anl_merge_inputs <- teal.transform::merge_expression_srv(
id = "anl_merge",
datasets = data,
join_keys = teal.data::join_keys(data),
selector_list = selector_list,
merge_function = "dplyr::inner_join"
)

adsl_merge_inputs <- teal.transform::merge_expression_module(
id = "adsl_merge",
datasets = data,
join_keys = teal.data::join_keys(data),
data_extract = list(arm_var = arm_var),
anl_name = "ANL_ADSL"
)

anl_q <- shiny::reactive({
qenv <- teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data))
qenv2 <- teal.code::eval_code(qenv, as.expression(anl_merge_inputs()$expr))
teal.code::eval_code(qenv2, as.expression(adsl_merge_inputs()$expr))
data() %>%
teal.code::eval_code(as.expression(anl_merge_inputs()$expr)) %>%
teal.code::eval_code(as.expression(adsl_merge_inputs()$expr))
})

validate_checks <- shiny::reactive({
Expand Down Expand Up @@ -540,14 +539,14 @@ srv_t_mult_events_byterm <- function(id,
all_q <- shiny::reactive({
validate_checks()

qenv <- anl_q()
anl_q <- anl_q()
anl_m <- anl_merge_inputs()

input_hlt <- names(anl_m$columns_source$hlt)
input_llt <- names(anl_m$columns_source$llt)

hlt_labels <- mapply(function(x) rtables::obj_label(qenv[["ANL"]][[x]]), input_hlt)
llt_labels <- mapply(function(x) rtables::obj_label(qenv[["ANL"]][[x]]), input_llt)
hlt_labels <- mapply(function(x) rtables::obj_label(anl_q[["ANL"]][[x]]), input_hlt)
llt_labels <- mapply(function(x) rtables::obj_label(anl_q[["ANL"]][[x]]), input_llt)

basic_table_args$title <- ifelse(
is.null(basic_table_args$title),
Expand All @@ -573,7 +572,7 @@ srv_t_mult_events_byterm <- function(id,
drop_arm_levels = input$drop_arm_levels,
basic_table_args = basic_table_args
)
teal.code::eval_code(qenv, as.expression(my_calls))
teal.code::eval_code(anl_q, as.expression(my_calls))
})

# Outputs to render.
Expand Down

0 comments on commit ce191a3

Please sign in to comment.