teal icon indicating copy to clipboard operation
teal copied to clipboard

Q: Should decorator show error from upstream `teal_data` (pre-decorated) in the UI?

Open averissimo opened this issue 1 year ago • 7 comments

          Do we want to have an error showing in the decorator's UI?

Using the example without X and Y

We might want to add a custom wrapper on srv_teal_transform_data that will return the original data if that has an error.

image

Originally posted by @averissimo in https://github.com/insightsengineering/teal.modules.general/issues/797#issuecomment-2490973081

averissimo avatar Nov 21 '24 12:11 averissimo

On the application below, we see a problem in Adverse Effects, which has errors coming from the encoding panel, but those are being shown in the decorator

library(teal)

decorator <- teal_transform_module(
  label = "Head",
  ui = function(id) shiny::checkboxInput(shiny::NS(id, "head_check"), "Show only first 6?", value = FALSE),
  server = make_teal_transform_server(
    quote({
      if (isTRUE(head_check)) iris <- head(iris, 6)
    })
  )
)

# Example below
init(
  data = teal_data() |> within(iris <- iris),
  modules = module(
    label = "Sample module",
    ui = function(id, decorators, ns = shiny::NS(id)) {
      shiny::tagList(
        shiny::tags$h4("🔵 Input with default encoding error"),
        shiny::checkboxInput(ns("check_me"), "Simulate error in data", FALSE),
        shiny::tags$h4("Decorator:"),
        ui_transform_teal_data(ns("decorator"), transformators = list(decorator)),
        shiny::tags$hr(),
        shiny::tags$h4("Output:"),
        shiny::verbatimTextOutput(ns("text"))
      )
    },
    server = function(id, data, decorators) {
      moduleServer(id, function(input, output, session) {
        table_q <- reactive({
          if (isFALSE(input$check_me)) {
            data()
          } else {
            within(data(), stop("Corrupted qenv with encoding error"))
          }
        })
        
        decorated_data <- srv_transform_teal_data("decorator", table_q, transformators = decorators)
        
        output$text <- shiny::renderPrint({
          req(table_q())
          decorated_data()[["iris"]]
        })
      })
    },
    ui_args = list(decorators = list(decorator)),
    server_args = list(decorators = list(decorator))
  )
) |> shiny::runApp()

averissimo avatar Dec 16 '24 14:12 averissimo

A possible solution:

  • Add a parameter to teal_transform_teal_data that prevents transformators from executing
    • Defaults to current behavior

averissimo avatar Dec 16 '24 14:12 averissimo

Is this not related to the discussion that we have here?

  • https://github.com/insightsengineering/teal/issues/1304

And the conclusion was

This is what we will do to handle the errors:

  1. We will display the error on the first transform failure with the error message that causes this error.
  2. The subsequent transforms will not run because an error occurred in the upstream transformation and show a generic error message.
  3. When this error happens, we will completely hide this module's output and display an error message instead of the output.

Doesn't this mean the issue that's being raised here is as designed?

donyunardi avatar Jan 16 '25 06:01 donyunardi

@donyunardi I think this is a bit different this time, please check @averissimo example from the opening of this issue

m7pr avatar Jan 16 '25 08:01 m7pr

It's a bit different, but similar to the teal_transform_module discussion. I feel like the overall principle should be - we report error at the very first step when an error occurs, so that the user can trace back to where the issue is. To me the screenshot from the issue looks fine on where we have error messages, are we talking about making the error message under transform module more clear here?

kumamiao avatar Jan 16 '25 18:01 kumamiao

@kumamiao error appeared on an Encoding Panel, since one of the inputs is missing. Error message got propagated to the decorator UI. The question is, should we show an error in decorator UI or not, if the error comes from Encoding Panel.

m7pr avatar Jan 21 '25 08:01 m7pr

After discussing with @kumamiao , we believe it would be best if errors occurring before the transformator/decorator:

  • Are not propagated to the transformator/decorator, as showing the error message there might mislead users into thinking the error originates from the transformator/decorator.
  • Grayed out the transformator/decorator UI box.
  • Bypass the transformator/decorator from evaluating and display the error message in a different location, such as the output area.

donyunardi avatar Jan 28 '25 03:01 donyunardi