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_t events by grade #1276

Conversation

llrs-roche
Copy link
Contributor

@llrs-roche llrs-roche commented Dec 3, 2024

Part of insightsengineering/teal#1371

Example with decorators
load_all("../teal")
load_all(".")
library(dplyr)

data <- teal_data()
data <- within(data, {
  ADSL <- tmc_ex_adsl
  .lbls_adae <- col_labels(tmc_ex_adae)
  ADAE <- tmc_ex_adae %>%
    mutate_if(is.character, as.factor) #' be certain of having factors
  col_labels(ADAE) <- .lbls_adae
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

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

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

app <- init(
  data = data,
  modules = modules(
    tm_t_events_by_grade(
      label = "Adverse Events by Grade Table",
      dataname = "ADAE",
      arm_var = choices_selected(c("ARM", "ARMCD"), "ARM"),
      llt = choices_selected(
        choices = variable_choices(ADAE, c("AETERM", "AEDECOD")),
        selected = c("AEDECOD")
      ),
      hlt = choices_selected(
        choices = variable_choices(ADAE, c("AEBODSYS", "AESOC")),
        selected = "AEBODSYS"
      ),
      grade = choices_selected(
        choices = variable_choices(ADAE, c("AETOXGR", "AESEV")),
        selected = "AETOXGR"
      ),
      decorators = list(insert_rrow_decorator())
    )
  )
)
shinyApp(app$ui, app$server)

@llrs-roche llrs-roche added the core label Dec 3, 2024
@llrs-roche llrs-roche changed the base branch from main to 1187_decorate_output@main December 3, 2024 14:51
@llrs-roche llrs-roche marked this pull request as ready for review December 4, 2024 09:19
@averissimo averissimo self-assigned this Dec 4, 2024
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.

LGTM! 🎉

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.

Wrong function documentation

@averissimo averissimo changed the title Tm t events by grade@1187 decorate output@main Introduce decorators for tm_t events by grade Dec 4, 2024
@llrs-roche llrs-roche requested a review from averissimo December 5, 2024 13:43
@m7pr
Copy link
Contributor

m7pr commented Dec 9, 2024

Leaving this for @averissimo to re-review

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.

Some changes to documentation, but mainly 1 question about when is pruned_and_sorted_result not created.

Great job here!

R/tm_t_events_by_grade.R Outdated Show resolved Hide resolved
R/tm_t_events_by_grade.R Outdated Show resolved Hide resolved
R/tm_t_events_by_grade.R Outdated Show resolved Hide resolved
@llrs-roche llrs-roche merged commit eb42bae into 1187_decorate_output@main Dec 11, 2024
1 check passed
@llrs-roche llrs-roche deleted the tm_t_events_by_grade@1187_decorate_output@main branch December 11, 2024 14:57
@github-actions github-actions bot locked and limited conversation to collaborators Dec 11, 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