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

Adds decorate functionality to module output #1357

Merged
merged 198 commits into from
Nov 29, 2024
Merged

Conversation

gogonzo
Copy link
Contributor

@gogonzo gogonzo commented Sep 30, 2024

closes #1383 #1384

Companion PRs:

example tmg app
pkgload::load_all("teal")
pkgload::load_all("teal.modules.general")
library(teal.widgets)

data <- teal_data()
data <- within(data, {
  require(nestcolor)
  ADSL <- rADSL
})
join_keys(data) <- default_cdisc_join_keys[c("ADSL")]

footnote_regression <- teal_transform_module(
  server = make_teal_transform_server(expression(
    plot <- plot + labs(caption = deparse(summary(fit)[[1]]))
  ))
)

fact_vars_adsl <- names(Filter(isTRUE, sapply(data[["ADSL"]], is.factor)))
vars <- choices_selected(variable_choices(data[["ADSL"]], fact_vars_adsl))

app <- init(
  data = data,
  modules = modules(
    tm_a_regression(
      label = "Regression",
      response = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = "BMRKR1",
          selected = "BMRKR1",
          multiple = FALSE,
          fixed = TRUE
        )
      ),
      regressor = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variables:",
          choices = variable_choices(data[["ADSL"]], c("AGE", "SEX", "RACE")),
          selected = "AGE",
          multiple = TRUE,
          fixed = FALSE
        )
      ),
      ggplot2_args = ggplot2_args(
        labs = list(subtitle = "Plot generated by Regression Module")
      ),
      decorators = list(footnote_regression)
    )
  )
)

shinyApp(app$ui, app$server)

@gogonzo gogonzo marked this pull request as draft September 30, 2024 08:22
R/modules.R Outdated Show resolved Hide resolved
R/module_nested_tabs.R Outdated Show resolved Hide resolved
R/modules.R Outdated Show resolved Hide resolved
R/teal_transform_module.R Outdated Show resolved Hide resolved
R/teal_transform_module.R Outdated Show resolved Hide resolved
R/teal_transform_module.R Outdated Show resolved Hide resolved
R/teal_transform_module.R Outdated Show resolved Hide resolved
R/teal_transform_module.R Outdated Show resolved Hide resolved
R/teal_transform_module.R Outdated Show resolved Hide resolved
R/teal_transform_module.R Outdated Show resolved Hide resolved
R/teal_transform_module.R Outdated Show resolved Hide resolved
R/teal_transform_module.R Outdated Show resolved Hide resolved
R/teal_transform_module.R Outdated Show resolved Hide resolved
Co-authored-by: Marcin <[email protected]>
Fixes comments on vignette example on #1357
averissimo added a commit to insightsengineering/teal.modules.general that referenced this pull request Nov 26, 2024
Partner to insightsengineering/teal#1357

<details><summary>Working Example </summary>

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

```

<details>

---------

Signed-off-by: André Veríssimo <[email protected]>
Co-authored-by: André Veríssimo <[email protected]>
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.

I'm not seeing the plot

image

vignettes/decorate-module-output.Rmd Outdated Show resolved Hide resolved
vignettes/decorate-module-output.Rmd Outdated Show resolved Hide resolved
vignettes/decorate-module-output.Rmd Outdated Show resolved Hide resolved
vignettes/decorate-module-output.Rmd Outdated Show resolved Hide resolved
m7pr and others added 6 commits November 29, 2024 15:02
Co-authored-by: André Veríssimo <[email protected]>
Signed-off-by: Marcin <[email protected]>
Co-authored-by: André Veríssimo <[email protected]>
Signed-off-by: Marcin <[email protected]>
Co-authored-by: André Veríssimo <[email protected]>
Signed-off-by: Marcin <[email protected]>
Co-authored-by: André Veríssimo <[email protected]>
Signed-off-by: Marcin <[email protected]>
Co-authored-by: André Veríssimo <[email protected]>
Signed-off-by: Marcin <[email protected]>
Co-authored-by: André Veríssimo <[email protected]>
Signed-off-by: Marcin <[email protected]>
Co-authored-by: Lluís Revilla <[email protected]>
Signed-off-by: André Veríssimo <[email protected]>
Copy link
Contributor

@llrs-roche llrs-roche left a comment

Choose a reason for hiding this comment

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

vignettes/decorate-module-output.Rmd Outdated Show resolved Hide resolved
@averissimo
Copy link
Contributor

averissimo commented Nov 29, 2024

Awesome work @gogonzo and @kpagacz on designing this, 🎩 off.

Thanks for the whole team working on reviewing and improving to what it is now and @m7pr for leading the effort 💪

Note: PR failing due to missing link of vignette that is created with this PR.. it's a 🐔 or 🥚 :-)

@averissimo averissimo merged commit d47b698 into main Nov 29, 2024
28 of 29 checks passed
@averissimo averissimo deleted the 1187_decorate_output@main branch November 29, 2024 16:55
@github-actions github-actions bot locked and limited conversation to collaborators Nov 29, 2024
@m7pr
Copy link
Contributor

m7pr commented Nov 29, 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.

[Feature Request]: Finalize decorate POC
7 participants