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

[Bug]: filter panel for related datanames of ANL are not shown #1298

Closed
gogonzo opened this issue Aug 8, 2024 · 2 comments · Fixed by #1334
Closed

[Bug]: filter panel for related datanames of ANL are not shown #1298

gogonzo opened this issue Aug 8, 2024 · 2 comments · Fixed by #1334
Assignees
Labels
bug Something isn't working core

Comments

@gogonzo
Copy link
Contributor

gogonzo commented Aug 8, 2024

What happened?

When ANL (or any new dataset) is created in teal_transform_module and teal_module is based on this new dataset only, then related datasets are ignored when building an application. For related datanames filter panel is not shown as they are not listed in module$datanames but only needed in teal_transform_module to successfully evaluate transform code.

We need a way to include related datanames also in the filter-panel and be able to filter them (in order to filter ANL indirectly).
Matter was discussed by the team and we sense that teal_transform_module needs datanames argument which can be set by app-developer, but also can have relevant default values.

example app
options(
  teal.log_level = "TRACE",
  teal.show_js_log = TRUE,
  # teal.bs_theme = bslib::bs_theme(version = 5),
  shiny.bookmarkStore = "server"
)

# pkgload::load_all("teal.data")
pkgload::load_all("teal.slice")
pkgload::load_all("teal")

anl_transformer <- list(
  teal_transform_module(
    label = "ANL",
    ui = function(id) {
      ns <- NS(id)
      tagList(
        div("This transformer adds ANL (ADSL + ADTTE)")
      )
    },
    server = function(id, data) {
      moduleServer(id, function(input, output, session) {
        reactive({
          within(data(), {
            ANL <- dplyr::inner_join(
              ADSL,
              ADTTE[c("STUDYID", "USUBJID", setdiff(colnames(ADTTE), colnames(ADSL)))],
              by = c("USUBJID", "STUDYID")
            )
          })
        })
      })
    }
  )
)

data <- teal_data_module(
  once = FALSE,
  ui = function(id) {
    ns <- NS(id)
    tagList(
      numericInput(ns("obs"), "Number of observations to show", 1000),
      actionButton(ns("submit"), label = "Submit")
    )
  },
  server = function(id, ...) {
    moduleServer(id, function(input, output, session) {
      logger::log_trace("example_module_transform2 initializing.")
      eventReactive(input$submit, {
        data <- teal_data() |>
          within(
            {
              logger::log_trace("Loading data")
              ADSL <- head(teal.data::rADSL, n = n)
              ADTTE <- teal.data::rADTTE
              aaa <- iris
              CO2 <- CO2
              factors <- names(Filter(isTRUE, vapply(CO2, is.factor, logical(1L))))
              CO2[factors] <- lapply(CO2[factors], as.character)
            },
            n = as.numeric(input$obs)
          )
        join_keys(data) <- default_cdisc_join_keys[c("ADSL", "ADTTE")]
        teal.data::datanames(data) <- c("CO2", "ADTTE", "aaa", "ADSL")
        data
      })
    })
  }
)

app <- teal::init(
  data = data,
  modules = list(
    example_module("anl from transform", dataname = "ANL", transformers = anl_transformer)
  ),
  filter = teal_slices(
    teal_slice("ADSL", "SEX"),
    teal_slice("ADSL", "AGE", selected = c(18L, 65L)),
    include_varnames = list(
      ADSL = c("SEX", "AGE")
    )
  )
)

runApp(app)

P.S.

When creating wrappers for example transform_merge_module it should be very easy to determine "related datanames" as they would have to be specified to construct the merge call. We think that problem of datanames exists only for generic teal_transform_module in situations when module$datanames don't contain related datanames (normally they do contain).

@donyunardi
Copy link
Contributor

donyunardi commented Aug 12, 2024

Acceptance Criteria

  • The dataset created by a transformer in a teal module should be included in the filter panel.
  • Users should be able to filter the new dataset created by the transformer.
  • Ensure proper validation and warnings are provided when something fails.

@gogonzo
Copy link
Contributor Author

gogonzo commented Sep 5, 2024

Closed by #1334

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core
Projects
None yet
3 participants