teal icon indicating copy to clipboard operation
teal copied to clipboard

[Feature Request]: More information showed about reasons why transofmrator failed

Open strebuh opened this issue 8 months ago • 4 comments

Feature description

When trying to transform output of the tm_variable_browser module instead of the ouptut I just get: "One of the transformators failed. Please check its inputs." , console doesn't show any error.

Image

It would be very helpful to have more information about error.

Code of Conduct

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

Contribution Guidelines

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

Security Policy

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

strebuh avatar Apr 25 '25 09:04 strebuh

@strebuh Could you provide the app code you used? It looks like the issue is in the teal_transform_moduleobject. So, having a look at that would help in testing this during feature development.

vedhav avatar Apr 25 '25 09:04 vedhav

I will also point out that there is a work in progress for creating a modular validation in PR https://github.com/insightsengineering/teal/pull/1509 which will provide some more clarity.

vedhav avatar Apr 25 '25 09:04 vedhav

sure, the let it be this:

`%>%` <- purrr::`%>%`

transformator_wbr <- teal::teal_transform_module(
  label = "Select scope of data",
  ui = function(id) {
    ns <- NS(id)
    tags$div(
      radioButtons(inputId = ns("dataScope"), label="", choices = c("all", "ignore constans", "ignore empty", "ignore constans and empty"), selected = "ignore constans and empty",
                   inline = FALSE,
                   width = NULL)
    )
  },
  server = function(id, data) {
    moduleServer(id, function(input, output, session) {
      print("data transformator")
      reactive({
        within(
          data(),
          {
            if(scope == "ignore constans and empty") {
              iris <- iris  %>% dplyr::select(dplyr::where(~dplyr::n_distinct(.) > 1)) %>% dplyr::select_if(colSums(!is.na(.)) > 0)
            } else if(scope == "ignore constans") {
              iris <- iris  %>% dplyr::select(where(~dplyr::n_distinct(.) > 1))
            } else if(scope == "ignore empty") {
              iris <- iris %>% dplyr::select_if(colSums(!is.na(.)) > 0)
            } else {
              iris <- iris
            }
          },
          scope = input$dataScope
        )
      })
    })
  }
)

main_plot_decorator <- teal::teal_transform_module(
  label = "Static decorator",
  server = function(id, data) {
    moduleServer(id, function(input, output, session) {
      print("data transformator")
      reactive({
        req(data())
        within(data(), {
          if(inherits(variable_plot_r, c("ggplot", "grob", "trellis", "Heatmap"))){
            main_plot <- main_plot +
            # variable_plot_r <- variable_plot_r +
                ggplot2::scale_fill_manual(values = c("red", "tan"))
          }
        })
      })
    })
  }
)


run_uivr_app <- function() {
  app <- teal::init(
    data = teal.data::teal_data(iris = iris %>% 
                                  dplyr::mutate(random = sample(
                                    c("alfa", "beta", "gamma"), nrow(.), replace = TRUE))
                                ),
    modules = teal::modules(
      teal.modules.general::tm_data_table(
        label = "Report", 
        datasets_selected = "iris",   
        dt_args = list(extensions = c("Buttons", "ColReorder", "FixedHeader", "SearchPanes")),
        dt_options = list(
          searching = FALSE,
          pageLength = 30,
          lengthMenu = c(5, 15, 25, 50, 100),
          scrollX = FALSE,
          dom = "lBrtip",
          buttons = c( "copy", "csv", "excel", "pdf"),
          colReorder = TRUE,
          fixedHeader = TRUE
        )),
      teal.modules.general::tm_variable_browser(dataname = "iris", parent_dataname = "iris",         
                                                ggplot2_args = teal.widgets::ggplot2_args(labs = list(y = "# of Variable", x = NULL)),
                                                transformators = list(transformator_wbr, main_plot_decorator)) # 
    )
  )
  shiny::shinyApp(ui = app$ui, server = app$server)
}

run_uivr_app()

strebuh avatar Apr 25 '25 10:04 strebuh

I think this is related to this question https://github.com/insightsengineering/teal.modules.general/issues/873 tm_variable_browser doesn't support decorators. In your decorator you try to change main_plot object created inside the module, but this module doesn't handle such object.

m7pr avatar Apr 25 '25 15:04 m7pr