Skip to content

Conversation

@m7pr
Copy link
Contributor

@m7pr m7pr commented Nov 18, 2024

Part of #863

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)
}

@m7pr m7pr added the core label Nov 18, 2024
@gogonzo gogonzo mentioned this pull request Nov 18, 2024
15 tasks
@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.

3 participants