Skip to content

Commit

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

```r
library(nestcolor)

ADSL <- tmc_ex_adsl
ADTTE <- tmc_ex_adtte
ADSL$RACE <- droplevels(ADSL$RACE) %>% formatters::with_label("Race")

arm_ref_comp <- list(
  ARM = list(
    ref = "B: Placebo",
    comp = c("A: Drug X", "C: Combination")
  ),
  ARMCD = list(
    ref = "ARM B",
    comp = c("ARM A", "ARM C")
  )
)

app <- init(
  data = cdisc_data(
    ADSL = ADSL,
    ADTTE = ADTTE,
    code = "
      ADSL <- tmc_ex_adsl
      ADTTE <- tmc_ex_adtte
      ADSL$RACE <- droplevels(ADSL$RACE) %>% formatters::with_label(\"Race\")
    "
  ),
  modules = modules(
    tm_g_forest_tte(
      label = "Forest Survival",
      dataname = "ADTTE",
      arm_var = choices_selected(
        variable_choices(ADSL, c("ARM", "ARMCD")),
        "ARMCD"
      ),
      arm_ref_comp = arm_ref_comp,
      paramcd = choices_selected(
        value_choices(ADTTE, "PARAMCD", "PARAM"),
        "OS"
      ),
      subgroup_var = choices_selected(
        variable_choices(ADSL, names(ADSL)),
        c("BMRKR2", "SEX")
      ),
      strata_var = choices_selected(
        variable_choices(ADSL, c("STRATA1", "STRATA2")),
        "STRATA2"
      ),
      plot_height = c(600, 200, 2000)
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}
```

---------

Signed-off-by: Vedha Viyash <[email protected]>
Co-authored-by: Aleksander Chlebowski <[email protected]>
  • Loading branch information
vedhav and chlebowa authored Nov 23, 2023
1 parent b3b53ec commit bded7c7
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions R/tm_g_forest_tte.R
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ srv_g_forest_tte <- function(id,
ggplot2_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(shiny::isolate(data()), "teal_data")

shiny::moduleServer(id, function(input, output, session) {
# Setup arm variable selection, default reference arms, and default
Expand All @@ -485,7 +486,7 @@ srv_g_forest_tte <- function(id,
input,
output,
id_arm_var = extract_input("arm_var", parentname),
data = data[[parentname]],
data = data()[[parentname]],
arm_ref_comp = arm_ref_comp,
module = "tm_g_forest_tte"
)
Expand Down Expand Up @@ -522,30 +523,27 @@ srv_g_forest_tte <- function(id,

anl_inputs <- teal.transform::merge_expression_srv(
datasets = data,
join_keys = teal.data::join_keys(data),
selector_list = selector_list,
merge_function = "dplyr::inner_join"
)

adsl_inputs <- teal.transform::merge_expression_module(
datasets = data,
join_keys = teal.data::join_keys(data),
data_extract = list(arm_var = arm_var, subgroup_var = subgroup_var, strata_var = strata_var),
anl_name = "ANL_ADSL"
)

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

validate_checks <- shiny::reactive({
teal::validate_inputs(iv_r())
qenv <- anl_q()
adsl_filtered <- qenv[[parentname]]
anl_filtered <- qenv[[dataname]]
anl <- qenv[["ANL"]]
adsl_filtered <- anl_q()[[parentname]]
anl_filtered <- anl_q()[[dataname]]
anl <- anl_q()[["ANL"]]

anl_m <- anl_inputs()
input_arm_var <- as.vector(anl_m$columns_source$arm_var)
Expand Down Expand Up @@ -605,7 +603,6 @@ srv_g_forest_tte <- function(id,
all_q <- shiny::reactive({
validate_checks()

qenv <- anl_q()
anl_m <- anl_inputs()

strata_var <- as.vector(anl_m$columns_source$strata_var)
Expand All @@ -629,7 +626,7 @@ srv_g_forest_tte <- function(id,
time_unit_var = as.vector(anl_m$columns_source$time_unit_var),
ggplot2_args = ggplot2_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 bded7c7

Please sign in to comment.