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]: Transformers initiate without access to data. #1473

Closed
3 tasks done
chlebowa opened this issue Jan 31, 2025 · 0 comments · Fixed by #1478
Closed
3 tasks done

[Bug]: Transformers initiate without access to data. #1473

chlebowa opened this issue Jan 31, 2025 · 0 comments · Fixed by #1478
Assignees
Labels
bug Something isn't working core

Comments

@chlebowa
Copy link
Contributor

chlebowa commented Jan 31, 2025

What happened?

Following the transformer vignette, I am trying to build a transformer module, which creates a selectInput with choices derived from the data.

code
library(teal)

data <- within(teal_data(), {
  iris <- iris
  mtcars <- mtcars
})

transformator_iris_scale <- teal_transform_module(
  label = "Scaling transformator for iris",
  ui = function(id) {
    ns <- NS(id)
    uiOutput(ns("scaled_columns_container"))
  },
  server = function(id, data) {
    moduleServer(id, function(input, output, session) {
      ns <- session$ns

      scalable_columns <- names(Filter(is.numeric, isolate(data())[["iris"]]))

      output$scaled_columns_container <- renderUI({
        selectInput(
          inputId = ns("scaled_columns"),
          label = "Columns to scale",
          choices = scalable_columns,
          selected = input$scaled_columns,
          multiple = TRUE
        )
      })

      reactive({
        data() # no-op for simplicity
      })
    })
  }
)

app <- init(
  data = data,
  modules = teal::example_module(transformators = list(transformator_iris_scale))
)

shinyApp(app$ui, app$server)

I used isolate(data()) in the module server function (not in a reactive and not in within) and I am not getting anything (no choices).

Upon inspection,

Browse[1]> data()
NULL
NOTE

The transformer in question was used as the second transformation to iris. When I drop in to the first one with browser, I get this:

Browse[1]> data()
Error: 

which looks like a req error.

WORKAROUND

In order to get it to work I had to replace

      scalable_columns <- names(Filter(is.numeric, isolate(data())[["iris"]]))

with

      scalable_columns <- reactive({
        names(Filter(is.numeric, data()[["iris"]]))
      })

which does work but it is something that should be mentioned in the vignette.

sessionInfo()

> packageVersion("teal")
[1] '0.15.2.9117'

Relevant log output

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.
@chlebowa chlebowa added the bug Something isn't working label Jan 31, 2025
@gogonzo gogonzo self-assigned this Feb 3, 2025
@gogonzo gogonzo added the core label Feb 4, 2025
@gogonzo gogonzo closed this as completed in 4bd73cf Feb 6, 2025
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
Development

Successfully merging a pull request may close this issue.

2 participants