Skip to content

[Bug]: Decorators does not work for tm_g_distribution's outputs summary_table and test_table #849

@vedhav

Description

@vedhav

What happened?

Example to reproduce:

devtools::load_all()

data <- teal_data(join_keys = default_cdisc_join_keys[c("ADSL", "ADRS")])
data <- within(data, {
  require(nestcolor)
  ADSL <- rADSL
  ADRS <- rADRS
})

# For tm_outliers
fact_vars_adsl <- names(Filter(isTRUE, sapply(data[["ADSL"]], is.factor)))
vars <- choices_selected(variable_choices(data[["ADSL"]], fact_vars_adsl))

table_decorator <- function(.color1 = "#f9f9f9", .color2 = "#f0f0f0", .var_to_replace = "table") {
  teal_transform_module(
    label = "Table color",
    ui = function(id) {
      selectInput(
        NS(id, "style"),
        "Table Style",
        choices = c("Default", "Color1", "Color2"),
        selected = "Default"
      )
    },
    server = function(id, data) {
      moduleServer(id, function(input, output, session) {
        logger::log_info("🔵 Table row color called to action!", namespace = "teal.modules.general")
        reactive({
          req(data(), input$style)
          logger::log_info("changing the Table row color '{input$style}'", namespace = "teal.modules.general")
          teal.code::eval_code(data(), substitute(
            {
              .var_to_replace <- switch(style,
                "Color1" = DT::formatStyle(
                  .var_to_replace,
                  columns = attr(.var_to_replace$x, "colnames")[-1],
                  target = "row",
                  backgroundColor = .color1
                ),
                "Color2" = DT::formatStyle(
                  .var_to_replace,
                  columns = attr(.var_to_replace$x, "colnames")[-1],
                  target = "row",
                  backgroundColor = .color2
                ),
                .var_to_replace
              )
            },
            env = list(
              style = input$style,
              .var_to_replace = as.name(.var_to_replace),
              .color1 = .color1,
              .color2 = .color2
            )
          ))
        })
      })
    }
  )
}

init(
  data = data,
  modules = modules(
    tm_g_distribution(
      dist_var = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")),
          selected = "BMRKR1",
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      strata_var = data_extract_spec(
        dataname = "ADSL",
        filter = filter_spec(
          vars = vars,
          multiple = TRUE
        )
      ),
      group_var = data_extract_spec(
        dataname = "ADSL",
        filter = filter_spec(
          vars = vars,
          multiple = TRUE
        )
      ),
      decorators = list(
        summary_table = table_decorator("summary_table", .color1 = "#f0000055"),
        test_table = table_decorator("test_table", .color1 = "#f0000055")
      )
    )
  )
) |> shiny::runApp()

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcore

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions