Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce decorators for tm_g_pp_adverse_events #1269

Conversation

m7pr
Copy link
Contributor

@m7pr m7pr commented Nov 28, 2024

Part of insightsengineering/teal#1371

Working Example
pkgload::load_all("../teal.modules.clinical", export_all = FALSE)

library(nestcolor)
library(dplyr)

data <- teal_data()
data <- within(data, {
  ADAE <- tmc_ex_adae
  ADSL <- tmc_ex_adsl %>%
    filter(USUBJID %in% ADAE$USUBJID)

  ADAE$ASTDY <- structure(
    as.double(ADAE$ASTDY, unit = attr(ADAE$ASTDY, "units", exact = TRUE)),
    label = attr(ADAE$ASTDY, "label", exact = TRUE)
  )
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

ADSL <- data[["ADSL"]]
ADAE <- data[["ADAE"]]

caption_decorator <- function(default_caption = "I am a good decorator", .var_to_replace = "plot") {
  teal_transform_module(
    label = "Caption",
    ui = function(id) shiny::textInput(shiny::NS(id, "footnote"), "Footnote", value = default_caption),
    server = make_teal_transform_server(
      substitute({
        .var_to_replace <- .var_to_replace + ggplot2::labs(caption = footnote)
      }, env = list(.var_to_replace = as.name(.var_to_replace)))
    )
  )
}

head_decorator <- function(default_value = 6, .var_to_replace = "object") {
  teal_transform_module(
    label = "Head",
    ui = function(id) shiny::numericInput(shiny::NS(id, "n"), "N rows", value = default_value),
    server = make_teal_transform_server(
      substitute({
        .var_to_replace <- utils::head(.var_to_replace, n = n)
      }, env = list(.var_to_replace = as.name(.var_to_replace)))
    )
  )
}

app <- init(
  data = data,
  modules = modules(
    tm_g_pp_adverse_events(
      label = "Adverse Events",
      dataname = "ADAE",
      parentname = "ADSL",
      patient_col = "USUBJID",
      plot_height = c(600L, 200L, 2000L),
      aeterm = choices_selected(
        choices = variable_choices(ADAE, "AETERM"),
        selected = "AETERM"
      ),
      tox_grade = choices_selected(
        choices = variable_choices(ADAE, "AETOXGR"),
        selected = "AETOXGR"
      ),
      causality = choices_selected(
        choices = variable_choices(ADAE, "AEREL"),
        selected = "AEREL"
      ),
      outcome = choices_selected(
        choices = variable_choices(ADAE, "AEOUT"),
        selected = "AEOUT"
      ),
      action = choices_selected(
        choices = variable_choices(ADAE, "AEACN"),
        selected = "AEACN"
      ),
      time = choices_selected(
        choices = variable_choices(ADAE, "ASTDY"),
        selected = "ASTDY"
      ),
      decod = NULL,
      decorators = list(plot = caption_decorator('Marcin', 'plot'), table = head_decorator(2, 'table'))
    )
  )
) |> shiny::runApp()

R/tm_g_pp_adverse_events.R Outdated Show resolved Hide resolved
Copy link
Contributor

@averissimo averissimo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example app works great.

Module appears to have a bug

@m7pr
Copy link
Contributor Author

m7pr commented Nov 29, 2024

@averissimo @llrs-roche beware before merging this module, it has a decorator for plot that is dependent on a decorator for a table. If table decorator breaks, you don't see a plot. This is the same scenario as in #1267 (comment)

@averissimo averissimo requested a review from llrs-roche December 4, 2024 12:38
@averissimo averissimo removed their assignment Dec 4, 2024
Copy link
Contributor

@llrs-roche llrs-roche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running the test I see this on the terminal when I try to create a card:

Error in self$set_content(table) : 
  Assertion on 'content' failed: Must inherit from class 'data.frame'/'rtables'/'TableTree'/'ElementaryTable'/'listing_df', but has class 'NULL'.
Warning in observe() :
  The card could not be added to the report. Have the outputs for the report been created yet? If not please try again when they are ready. Otherwise contact your application developer

Which prevents the shiny app to generate the card.

I also left two minor comments

R/tm_g_pp_adverse_events.R Outdated Show resolved Hide resolved
R/tm_g_pp_adverse_events.R Show resolved Hide resolved
@averissimo averissimo requested a review from llrs-roche December 5, 2024 16:22
@m7pr m7pr merged commit a6e730c into 1187_decorate_output@main Dec 9, 2024
1 check passed
@m7pr m7pr deleted the tm_g_pp_adverse_events@1187_decorate_output@main branch December 9, 2024 13:16
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants