Skip to content

Conversation

@m7pr
Copy link
Contributor

@m7pr m7pr commented Nov 19, 2024

Part of #863

Working Example
devtools::load_all("../teal")
devtools::load_all(".")
interactive_decorator <- teal_transform_module(
  ui = function(id) {
    ns <- NS(id)
    div(
      textInput(ns("x_axis_title_top"), "X axis title plot top", value = "x axis top"),
      textInput(ns("x_axis_title_bottom"), "X axis title plot bottom", value = "x axis bottom")
    )
  },
  server = function(id, data) {
    moduleServer(id, function(input, output, session) {
      reactive({
        req(data())
        within(data(),
               {
                 plot_bottom <- plot_bottom + xlab(my_title_bottom)
                 plot_top <- plot_top + xlab(my_title_top)
               },
               my_title_top = input$x_axis_title_top,
               my_title_bottom = input$x_axis_title_bottom
        )
      })
    })
  }
)

# general data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  CO2 <- CO2
  factors <- names(Filter(isTRUE, vapply(CO2, is.factor, logical(1L))))
  CO2[factors] <- lapply(CO2[factors], as.character)
})

app <- init(
  data = data,
  modules = modules(
    tm_g_association(
      ref = data_extract_spec(
        dataname = "CO2",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")),
          selected = "Plant",
          fixed = FALSE
        )
      ),
      vars = data_extract_spec(
        dataname = "CO2",
        select = select_spec(
          label = "Select variables:",
          choices = variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")),
          selected = "Treatment",
          multiple = TRUE,
          fixed = FALSE
        )
      ),
      decorators = list(interactive_decorator)
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

@m7pr m7pr added the core label Nov 19, 2024
@gogonzo gogonzo mentioned this pull request Nov 19, 2024
15 tasks
@m7pr m7pr changed the title introduce decorators for tm_g_association WIP introduce decorators for tm_g_association Nov 20, 2024
@m7pr m7pr changed the title WIP introduce decorators for tm_g_association introduce decorators for tm_g_association Nov 22, 2024
@m7pr m7pr requested a review from averissimo November 22, 2024 12:36
@m7pr m7pr marked this pull request as ready for review November 22, 2024 12:36
Copy link
Contributor

@averissimo averissimo left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

@averissimo averissimo merged commit b6ca759 into 1187_decorate_output@main Nov 22, 2024
1 check passed
@averissimo averissimo deleted the tm_association@1187_decorate_output@main branch November 22, 2024 17:54
@github-actions github-actions bot locked and limited conversation to collaborators Nov 22, 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