Skip to content

Commit

Permalink
tdata to teal_data - tm_t_tte (#857)
Browse files Browse the repository at this point in the history
Example app
```

ADSL <- tmc_ex_adsl
ADTTE <- tmc_ex_adtte

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")
  )
)

app <- init(
  data = cdisc_data(
    ADSL = ADSL,
    ADTTE = ADTTE,
    code = "
      ADSL <- tmc_ex_adsl
      ADTTE <- tmc_ex_adtte
    "
  ),
  modules = modules(
    tm_t_tte(
      label = "Time To Event Table",
      dataname = "ADTTE",
      arm_var = choices_selected(
        variable_choices(ADSL, c("ARM", "ARMCD", "ACTARMCD")),
        "ARM"
      ),
      arm_ref_comp = arm_ref_comp,
      paramcd = choices_selected(
        value_choices(ADTTE, "PARAMCD", "PARAM"),
        "OS"
      ),
      strata_var = choices_selected(
        variable_choices(ADSL, c("SEX", "BMRKR2")),
        "SEX"
      ),
      time_points = choices_selected(c(182, 243), 182),
      event_desc_var = choices_selected(
        variable_choices(ADTTE, "EVNTDESC"),
        "EVNTDESC",
        fixed = TRUE
      )
    )
  )
)
shinyApp(app$ui, app$server)
```
  • Loading branch information
kartikeyakirar authored Nov 23, 2023
1 parent 938bc6e commit 83536ff
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions R/tm_t_tte.R
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,8 @@ srv_t_tte <- 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) {
# Setup arm variable selection, default reference arms, and default
# comparison arms for encoding panel
Expand All @@ -731,7 +732,7 @@ srv_t_tte <- function(id,
input,
output,
id_arm_var = extract_input("arm_var", parentname),
data = data[[parentname]],
data = reactive(data()[[parentname]]),
arm_ref_comp = arm_ref_comp,
module = "tm_t_tte",
on_off = shiny::reactive(input$compare_arms)
Expand Down Expand Up @@ -796,7 +797,6 @@ srv_t_tte <- function(id,
anl_merge_inputs <- teal.transform::merge_expression_srv(
datasets = data,
selector_list = selector_list,
join_keys = teal.data::join_keys(data),
merge_function = "dplyr::inner_join"
)

Expand All @@ -808,9 +808,9 @@ srv_t_tte <- function(id,
)

anl_q <- shiny::reactive({
qenv <- teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data))
qenv1 <- teal.code::eval_code(qenv, as.expression(anl_merge_inputs()$expr))
teal.code::eval_code(qenv1, 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))
})

# Prepare the analysis environment (filter data, check data, populate envir).
Expand Down Expand Up @@ -869,7 +869,6 @@ srv_t_tte <- function(id,
validate_checks()

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

strata_var <- as.vector(anl_m$columns_source$strata_var)

Expand Down Expand Up @@ -909,7 +908,7 @@ srv_t_tte <- function(id,
basic_table_args = basic_table_args
)

teal.code::eval_code(qenv, as.expression(my_calls))
anl_q() %>% teal.code::eval_code(as.expression(my_calls))
})

table_r <- shiny::reactive(all_q()[["table"]])
Expand Down

0 comments on commit 83536ff

Please sign in to comment.