insightsengineering / teal.slice

Reproducible slice module for teal applications
https://insightsengineering.github.io/teal.slice/
Other
11 stars 5 forks source link

unexplained error #560

Closed chlebowa closed 5 months ago

chlebowa commented 5 months ago

Error when attempting to run the example app for teal.modules.general::tm_a_regression.

library(teal.modules.general)
library(teal.widgets)

data <- teal_data()
data <- within(data, {
  library(nestcolor)
  CO2 <- CO2
})
datanames <- c("CO2")
datanames(data) <- datanames

app <- init(
  data = data,
  modules = modules(
    tm_a_regression(
      label = "Regression",
      response = data_extract_spec(
        dataname = "CO2",
        select = select_spec(
          label = "Select variable:",
          choices = "uptake",
          selected = "uptake",
          multiple = FALSE,
          fixed = TRUE
        )
      ),
      regressor = data_extract_spec(
        dataname = "CO2",
        select = select_spec(
          label = "Select variables:",
          choices = variable_choices(data[["CO2"]], c("conc", "Treatment")),
          selected = "conc",
          multiple = TRUE,
          fixed = FALSE
        )
      ),
      ggplot2_args = ggplot2_args(
        labs = list(subtitle = "Plot generated by Regression Module")
      )
    )
  )
)
runApp(app, launch.browser = TRUE)
[INFO] 2024-02-19 14:17:59.8422 pid:70568 token:[dcda081b] teal Initializing reporter_previewer_module
Warning: Error in super$initialize: Assertion on 'label' failed: Must be of type 'character' (or 'NULL'), not 'list'.
  3: runApp
  2: print.shiny.appobj
  1: <Anonymous>
chlebowa commented 5 months ago

The app works all right with iris. I saw the same error when trying to use the CO2 dataset with another example app.

chlebowa commented 5 months ago

Error goes away if CO2 is passed through CO2 <- as.data.frame(CO2) CO2 <- data.frame(CO2). This is most likely connected to the labels attribute of the dataset.

averissimo commented 5 months ago

Exactly, attr(dataset, "label", exact = TRUE) on teal.slice::init_filtered_dataset would solve the issue

averissimo commented 5 months ago

That is, when trying to extrapolate the label on the S3 method arguments an exact match would solve this.

A (?better?) alternative would be to ignore the default value if attr(dataset, "label") is not a string (with or without the exact = TRUE).

edit: although this would a lot of complexity to the argument code

chlebowa commented 5 months ago

I think ensuring exact matching is the better way to go.

I guess this should be moved to teal.slice then. Would you do the honors?