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_outliers #805

Merged

Conversation

m7pr
Copy link
Contributor

@m7pr m7pr commented Nov 20, 2024

Partner to insightsengineering/teal#1357

Working Example
devtools::load_all('../teal')
devtools::load_all('.')
# general data example
data <- teal_data()
data <- within(data, {
  CO2 <- CO2
  CO2[["primary_key"]] <- seq_len(nrow(CO2))
})
join_keys(data) <- join_keys(join_key("CO2", "CO2", "primary_key"))

vars <- choices_selected(variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")))


boxplot_decorator <- teal_transform_module(
  label = "Footnote",
  ui = function(id) shiny::textInput(shiny::NS(id, "footnote"), "Box plot Footnote", value = "BOX PLOT I am a good decorator"),
  server = function(id, data) {
    moduleServer(id, function(input, output, session) {
      logger::log_info("🟢 Footnote called to action!", namespace = "teal.modules.general")
      reactive(
        within(
          data(),
          {
            if (exists("box_plot")) {
              footnote_str <- footnote
              box_plot <- box_plot + ggplot2::labs(caption = footnote_str)
            }
          },
          footnote = input$footnote
        )
      )
    })
  }
)

cum_dist_decorator <- teal_transform_module(
  label = "Footnote",
  ui = function(id) shiny::textInput(shiny::NS(id, "footnote"), "Cum dist Footnote", value = "CUM DIST I am a good decorator"),
  server = function(id, data) {
    moduleServer(id, function(input, output, session) {
      logger::log_info("🟢 Footnote called to action!", namespace = "teal.modules.general")
      reactive(
        within(
          data(),
          {
            if (exists("cum_dist_plot")) {
              footnote_str <- footnote
              cum_dist_plot <- cum_dist_plot + ggplot2::labs(caption = footnote_str)
            }
          },
          footnote = input$footnote
        )
      )
    })
  }
)

app <- init(
  data = data,
  modules = modules(
    tm_outliers(
      outlier_var = list(
        data_extract_spec(
          dataname = "CO2",
          select = select_spec(
            label = "Select variable:",
            choices = variable_choices(data[["CO2"]], c("conc", "uptake")),
            selected = "uptake",
            multiple = FALSE,
            fixed = FALSE
          )
        )
      ),
      categorical_var = list(
        data_extract_spec(
          dataname = "CO2",
          filter = filter_spec(
            vars = vars,
            choices = value_choices(data[["CO2"]], vars$selected),
            selected = value_choices(data[["CO2"]], vars$selected),
            multiple = TRUE
          )
        )
      ),
      decorators = list(boxplot_decorator, cum_dist_decorator)
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

@m7pr m7pr changed the base branch from main to 1187_decorate_output@main November 20, 2024 13:53
@m7pr m7pr requested a review from averissimo November 20, 2024 13:53
@m7pr m7pr added the core label Nov 20, 2024
@m7pr m7pr removed the request for review from averissimo November 20, 2024 13:54
@m7pr m7pr changed the title introduce decorators for tm_outliers WIP introduce decorators for tm_outliers Nov 20, 2024
@m7pr m7pr changed the title WIP introduce decorators for tm_outliers introduce decorators for tm_outliers Nov 25, 2024
@m7pr m7pr marked this pull request as ready for review November 25, 2024 13:00
R/tm_outliers.R Outdated Show resolved Hide resolved
@averissimo averissimo merged commit 817123a into 1187_decorate_output@main Nov 26, 2024
1 check passed
@averissimo averissimo deleted the tm_outliers@1187_decorate_output@main branch November 26, 2024 11:07
@github-actions github-actions bot locked and limited conversation to collaborators Nov 26, 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