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

introduce decorators for tm_g_bivariate #797

Merged
merged 15 commits into from
Nov 21, 2024

Conversation

m7pr
Copy link
Contributor

@m7pr m7pr commented Nov 18, 2024

Part of insightsengineering/teal#1370

Working Example
devtools::load_all("../teal")
devtools::load_all(".")
library(ggplot2)
interactive_decorator <- teal_transform_module(
  ui = function(id) {
    ns <- NS(id)
    div(
      textInput(ns("x_axis_title"), "X axis title", value = "x axis")
    )
  },
  server = function(id, data) {
    moduleServer(id, function(input, output, session) {
      reactive({
        req(data())
        within(data(),
               {
                 plot <- plot +
                   xlab(my_title)
               },
               my_title = input$x_axis_title
        )
      })
    })
  }
)
# general data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  CO2 <- data.frame(CO2)
})

app <- init(
  data = data,
  modules = tm_g_bivariate(
    x = data_extract_spec(
      dataname = "CO2",
      select = select_spec(
        label = "Select variable:",
        choices = variable_choices(data[["CO2"]]),
        selected = "conc",
        fixed = FALSE
      )
    ),
    y = data_extract_spec(
      dataname = "CO2",
      select = select_spec(
        label = "Select variable:",
        choices = variable_choices(data[["CO2"]]),
        selected = "uptake",
        multiple = FALSE,
        fixed = FALSE
      )
    ),
    row_facet = data_extract_spec(
      dataname = "CO2",
      select = select_spec(
        label = "Select variable:",
        choices = variable_choices(data[["CO2"]]),
        selected = "Type",
        fixed = FALSE
      )
    ),
    col_facet = data_extract_spec(
      dataname = "CO2",
      select = select_spec(
        label = "Select variable:",
        choices = variable_choices(data[["CO2"]]),
        selected = "Treatment",
        fixed = FALSE
      )
    ),
    decorators = list(interactive_decorator)
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

R/tm_g_bivariate.R Outdated Show resolved Hide resolved
R/tm_g_bivariate.R Outdated Show resolved Hide resolved
R/tm_g_bivariate.R Outdated Show resolved Hide resolved
R/tm_g_bivariate.R Outdated Show resolved Hide resolved
R/tm_g_bivariate.R Outdated Show resolved Hide resolved
R/tm_g_bivariate.R Outdated Show resolved Hide resolved
@m7pr m7pr marked this pull request as ready for review November 20, 2024 10:53
@averissimo
Copy link
Contributor

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

@m7pr m7pr merged commit cf4371f into 1187_decorate_output@main Nov 21, 2024
1 check passed
@m7pr m7pr deleted the tm_bivariate@1187_decorate_output@main branch November 21, 2024 15:12
@github-actions github-actions bot locked and limited conversation to collaborators Nov 21, 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.

2 participants