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

Have different constructor for "Data" module and "Transform" module #1283

Merged

Conversation

vedhav
Copy link
Contributor

@vedhav vedhav commented Aug 1, 2024

Adds teal_transform_module() to be used to create data modules for transformation.

Example usage

library(teal)
data <- teal_data() %>%
  within({
    iris <- iris
    mtcars <- mtcars
  })
my_transformers <- list(
  teal_transform_module(
    label = "Custom transform for iris",
    ui = function(id) {
      ns <- NS(id)
      tags$div(
        numericInput(ns("n_rows"), "Number of rows to subset", value = 6, min = 1, max = 150, step = 1)
      )
    },
    server = function(id, data) {
      moduleServer(id, function(input, output, session) {
        reactive({
          data() %>%
            within(
              {
                iris <- head(iris, num_rows)
              },
              num_rows = input$n_rows
            )
        })
      })
    }
  )
)
app <- init(
  data = data,
  modules = example_module(transformers = my_transformers)
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

@vedhav vedhav mentioned this pull request Aug 1, 2024
63 tasks
Copy link
Contributor

@gogonzo gogonzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please link [teal_transform_module()] in description transformers argument in docs of teal_module function. Please review current teal_module and teal_transform_module documentation and write comprehensive description aimed for app developer - app developer needs to know everything about how teal_transform_module and teal_module works, but don't need to know FilteredData. What I mean by this is that you did right writing "passed through filter panel" but writing "modules" should not occur in this case. App developer needs to understand that teal_data object is sequenced through all teal_transform_modules' servers (it is a list) and eventually it is handed over to the server of teal_module

Roxygen docs should be more technical, while vignette should be focused on usage

Would be nice if @donyunardi looked at this content

R/teal_data_module.R Outdated Show resolved Hide resolved
R/teal_data_module.R Outdated Show resolved Hide resolved
R/teal_data_module.R Outdated Show resolved Hide resolved
R/teal_data_module.R Outdated Show resolved Hide resolved
@vedhav vedhav added the core label Aug 1, 2024
@donyunardi donyunardi self-requested a review August 1, 2024 23:19
Copy link
Contributor

@donyunardi donyunardi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provided some alternative to the content.

mtcars <- mtcars
})

my_transformers <- list(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're only using one teal_transform_module, perhaps we don't need to wrap it in a list? This will set the stage for the next example when we do have multiple teal_transform_modules wrapped in a list.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it makes sense, but let me think about this. Currently we have:

  • module is wrapped by modules
  • teal_slice is wrapped teal_slices
  • teal_data_module is not wrapped by anything
  • teal_transform_module is wrapped by list()

vignettes/data-transform-as-shiny-module.Rmd Outdated Show resolved Hide resolved

app <- init(
data = data,
modules = example_module()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use a very simple module() so that it's clear that transformer is passed as an argument to this function?

Copy link
Contributor

@gogonzo gogonzo Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think vignette should elaborate more about creating module which consumes transformers.

I've updated description here: #1231

R/teal_data_module.R Outdated Show resolved Hide resolved
@gogonzo gogonzo merged commit f251aa6 into 669_insertUI@main Aug 2, 2024
1 check passed
@gogonzo gogonzo deleted the constructor-for-transform-module@669_insertUI@main branch August 2, 2024 07:26
@github-actions github-actions bot locked and limited conversation to collaborators Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants