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

Duplicated decorators during an edge case of named and unnamed decorators #1325

Merged
merged 6 commits into from
Feb 7, 2025

Conversation

m7pr
Copy link
Contributor

@m7pr m7pr commented Jan 28, 2025

Fixes #1316

Companion in tmg insightsengineering/teal.modules.general#835

There was an issue where decorators got duplicated when you passed a combination of named an unnamed decorators into the module. This module has 2 objects, so if you pass 1 unnamed decorators and one named, there should be only 3 decorators visible (1 unnamed passed to all 2, and one named pass to one named).

On feature branch

image

On main

image
Code
pkgload::load_all(".", 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({
        
      }, 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({
        
      }, 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'), 
                        caption_decorator('Marcin', 'plot')
                        )
    )
  )
) |> shiny::runApp()

@llrs-roche llrs-roche self-assigned this Jan 29, 2025
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.

Note that the CI is failing. See the linter and the comment of Dawid on tmg.

@m7pr
Copy link
Contributor Author

m7pr commented Jan 31, 2025

In the end allowed either all named or all unnamed decorators

Copy link
Contributor

github-actions bot commented Jan 31, 2025

Unit Tests Summary

    1 files     70 suites   1h 11m 13s ⏱️
  727 tests   614 ✅ 113 💤 0 ❌
1 987 runs  1 759 ✅ 228 💤 0 ❌

Results for commit ca761ee.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Jan 31, 2025

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
shinytest2-tm_a_mmrm 💔 $747.84$ $+3.91$ $0$ $0$ $0$ $0$
shinytest2-tm_g_forest_rsp 💔 $177.26$ $+1.65$ $0$ $0$ $0$ $0$
shinytest2-tm_g_km 💔 $274.05$ $+1.05$ $0$ $0$ $0$ $0$
shinytest2-tm_g_pp_adverse_events 💔 $127.39$ $+1.04$ $0$ $0$ $0$ $0$
shinytest2-tm_g_pp_therapy 💔 $197.72$ $+1.57$ $0$ $0$ $0$ $0$
shinytest2-tm_t_abnormality_by_worst_grade 💔 $68.07$ $+1.02$ $0$ $0$ $0$ $0$
shinytest2-tm_t_binary_outcome 💚 $79.79$ $-1.06$ $0$ $0$ $0$ $0$
shinytest2-tm_t_pp_prior_medication 💔 $79.05$ $+1.13$ $0$ $0$ $0$ $0$
shinytest2-tm_t_shift_by_arm_by_worst 💔 $92.48$ $+1.13$ $0$ $0$ $0$ $0$
shinytest2-tm_t_shift_by_grade 💔 $79.85$ $+1.33$ $0$ $0$ $0$ $0$
shinytest2-tm_t_summary_by 💚 $84.01$ $-2.55$ $0$ $0$ $0$ $0$
shinytest2-tm_t_tte 💚 $70.77$ $-2.57$ $0$ $0$ $0$ $0$

Results for commit 0b8c3a6

♻️ This comment has been updated with latest results.

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.

I like the decision to only allow named or unnamed decorators, as the code is the same for tmg and there you provided an updated code example I replied there. The messages the users get and the code do not always match. See insightsengineering/teal.modules.general#835 (review)

…assert_decorators, and let it pass through normalize_decorators
m7pr added a commit to insightsengineering/teal.modules.general that referenced this pull request Feb 7, 2025
…tors (#835)

Companion to
insightsengineering/teal.modules.clinical#1325

---------

Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
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.

Same behavior as on TMG. Good work

@llrs-roche llrs-roche merged commit a3ec420 into main Feb 7, 2025
26 checks passed
@llrs-roche llrs-roche deleted the 1316_duplicates@main branch February 7, 2025 14:34
@github-actions github-actions bot locked and limited conversation to collaborators Feb 7, 2025
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.

[Bug]: multiplied decorators
2 participants