Skip to content

{teal} module returns a teal_report object that extends from teal_data #884

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

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
78d35c9
wip
gogonzo May 20, 2025
38ee62e
Merge branch 'teal_data_report' into teal_reportable
gogonzo May 27, 2025
9c498c1
WIP implementation of teal_reportable
gogonzo May 27, 2025
334509b
no need to grid.draw grobs
gogonzo Jun 3, 2025
61ab554
replace grob with grid output
gogonzo Jun 3, 2025
2d091a5
Merge remote-tracking branch 'origin/main' into teal_reportable
gogonzo Jun 4, 2025
8162a8c
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jun 5, 2025
e734d5c
Naming (#885)
m7pr Jun 6, 2025
f0600dc
feat: improvements to tm_missing
averissimo Jun 6, 2025
ad5299c
feat: support argument rename and clean function body (#888)
averissimo Jun 17, 2025
c283343
fix srv_decorate_teal_data expression check
m7pr Jun 17, 2025
ba0e71e
rewrite modules to `teal_reportable` (#887)
m7pr Jun 18, 2025
38eb4a5
use_evaluate WIP
gogonzo Jun 18, 2025
c8f488a
WIP on use_evaluate
gogonzo Jun 19, 2025
719fdaa
Merge branch 'main' into use_evaluate
gogonzo Jun 26, 2025
6ed5cbd
Merge branch 'use_evaluate' into teal_reportable
gogonzo Jun 26, 2025
3db8aaa
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jun 26, 2025
1384b90
remotes
gogonzo Jul 2, 2025
0ef73eb
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jul 2, 2025
c0a2880
missing prefixes
m7pr Jul 2, 2025
d61561f
bring back sentence in tm_a_pca
m7pr Jul 2, 2025
6773637
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jul 2, 2025
0f74447
add Module's code section header to divide code preparation with data…
m7pr Jul 2, 2025
630204b
change moment where datatable is created for tm_missing_data
m7pr Jul 2, 2025
e3b5a0b
Update R/tm_outliers.R
m7pr Jul 2, 2025
fdd9f89
do not reshape data into DT in tm_outliers - only do that for printin…
m7pr Jul 2, 2025
0f82001
Merge branch 'teal_reportable' of https://github.com/insightsengineer…
m7pr Jul 2, 2025
9b324b0
make Module's code section with two ## - so it's h2 instead of h1
m7pr Jul 2, 2025
83e41a5
Update R/tm_a_pca.R
averissimo Jul 7, 2025
229def2
Update R/tm_a_pca.R
averissimo Jul 7, 2025
6fc9beb
[skip style] [skip vbump] Restyle files
github-actions[bot] Jul 7, 2025
6d86ebc
chore: fix long line
averissimo Jul 7, 2025
508e3b2
[skip style] [skip vbump] Restyle files
github-actions[bot] Jul 7, 2025
3f82dca
chore: remove linter rule
averissimo Jul 7, 2025
45b9080
Merge branch 'main' into teal_reportable
m7pr Jul 8, 2025
52b4d59
substitute append.teal_card with c.teal_card
m7pr Jul 10, 2025
162b917
[skip style] [skip vbump] Restyle files
github-actions[bot] Jul 10, 2025
df02409
chore: lintr using quotes rule with double column and period at the end
averissimo Jul 10, 2025
7c2dc13
[skip style] [skip vbump] Restyle files
github-actions[bot] Jul 10, 2025
85f15de
Update R/tm_g_bivariate.R
m7pr Jul 11, 2025
5ad53e9
Update R/tm_missing_data.R
m7pr Jul 11, 2025
3bbf228
Update R/tm_t_crosstable.R
m7pr Jul 11, 2025
b64c3d7
missing assignment
m7pr Jul 11, 2025
16c525b
Update R/tm_g_association.R
averissimo Jul 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ VignetteBuilder:
rmarkdown
Remotes:
insightsengineering/teal.logger@main,
insightsengineering/teal.reporter@main,
insightsengineering/teal.reporter@teal_reportable,
insightsengineering/teal.transform@main,
insightsengineering/teal.widgets@main,
insightsengineering/teal@main
insightsengineering/teal@teal_reportable,
Config/Needs/verdepcheck: haleyjeppson/ggmosaic, tidyverse/ggplot2,
rstudio/shiny, insightsengineering/teal,
insightsengineering/teal.slice, insightsengineering/teal.transform,
Expand Down
59 changes: 18 additions & 41 deletions R/tm_a_pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
#' For additional details and examples of decorators, refer to the vignette
#' `vignette("decorate-module-output", package = "teal.modules.general")`.
#'
#' To learn more please refer to the vignette
#' `vignette("transform-module-output", package = "teal")` or the [`teal::teal_transform_module()`] documentation.
#' @inheritSection teal::example_module Reporting
#'
#' @examplesShinylive
#' library(teal.modules.general)
Expand Down Expand Up @@ -235,9 +234,6 @@
uiOutput(ns("all_plots"))
),
encoding = tags$div(
### Reporter
teal.reporter::simple_reporter_ui(ns("simple_reporter")),
###
tags$label("Encodings", class = "text-primary"),
teal.transform::datanames_input(args["dat"]),
teal.transform::data_extract_ui(
Expand Down Expand Up @@ -353,9 +349,7 @@
}

# Server function for the PCA module
srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, plot_width, ggplot2_args, decorators) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
srv_a_pca <- function(id, data, dat, plot_height, plot_width, ggplot2_args, decorators) {
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
Expand Down Expand Up @@ -436,9 +430,11 @@
selector_list = selector_list,
datasets = data
)
qenv <- reactive(
teal.code::eval_code(data(), 'library("ggplot2");library("dplyr");library("tidyr")') # nolint quotes
)
qenv <- reactive({
obj <- data()
teal.reporter::teal_card(obj) <- append(teal.reporter::teal_card(obj), "# Principal Component Analysis", after = 0)

Check warning on line 435 in R/tm_a_pca.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/tm_a_pca.R,line=435,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 121 characters.
teal.code::eval_code(obj, 'library("ggplot2");library("dplyr");library("tidyr")') # nolint quotes
})
anl_merged_q <- reactive({
req(anl_merged_input())
qenv() %>%
Expand Down Expand Up @@ -514,6 +510,8 @@
)
)

teal.reporter::teal_card(qenv) <- append(teal.reporter::teal_card(qenv), "## Principal Components Table")

qenv <- teal.code::eval_code(
qenv,
quote({
Expand All @@ -522,6 +520,8 @@
})
)

teal.reporter::teal_card(qenv) <- append(teal.reporter::teal_card(qenv), "## Eigenvectors Table")

teal.code::eval_code(
qenv,
quote({
Expand Down Expand Up @@ -602,7 +602,7 @@
),
ggtheme = ggtheme
)

teal.reporter::teal_card(base_q) <- append(teal.reporter::teal_card(base_q), "## Elbow plot")
teal.code::eval_code(
base_q,
substitute(
Expand Down Expand Up @@ -679,6 +679,7 @@
ggtheme = ggtheme
)

teal.reporter::teal_card(base_q) <- append(teal.reporter::teal_card(base_q), "## Circle plot")
teal.code::eval_code(
base_q,
substitute(
Expand Down Expand Up @@ -737,6 +738,7 @@
size <- input$size
font_size <- input$font_size

teal_card(base_q) <- append(teal_card(base_q), "## Biplot")
qenv <- teal.code::eval_code(
qenv,
substitute(
Expand Down Expand Up @@ -997,6 +999,7 @@
parsed_ggplot2_args$theme
)

teal_card(base_q) <- append(teal_card(base_q), "## Eigenvector plot")
teal.code::eval_code(
base_q,
substitute(
Expand Down Expand Up @@ -1038,9 +1041,8 @@
data = q,
decorators = select_decorators(decorators, obj_name),
expr = reactive({
substitute(print(.plot), env = list(.plot = as.name(obj_name)))
}),
expr_is_reactive = TRUE
substitute(.plot, env = list(.plot = as.name(obj_name)))
})
)
},
names(output_q),
Expand Down Expand Up @@ -1132,31 +1134,6 @@
verbatim_content = source_code_r,
title = "R Code for PCA"
)

### REPORTER
if (with_reporter) {
card_fun <- function(comment, label) {
card <- teal::report_card_template(
title = "Principal Component Analysis Plot",
label = label,
with_filter = with_filter,
filter_panel_api = filter_panel_api
)
card$append_text("Principal Components Table", "header3")
card$append_table(computation()[["tbl_importance"]])
card$append_text("Eigenvectors Table", "header3")
card$append_table(computation()[["tbl_eigenvector"]])
card$append_text("Plot", "header3")
card$append_plot(plot_r(), dim = pws$dim())
if (!comment == "") {
card$append_text("Comment", "header3")
card$append_text(comment)
}
card$append_src(source_code_r())
card
}
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
}
###
decorated_output_q
})
}
57 changes: 20 additions & 37 deletions R/tm_a_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
#' To learn more please refer to the vignette
#' `vignette("transform-module-output", package = "teal")` or the [`teal::teal_transform_module()`] documentation.
#'
#' @inheritSection teal::example_module Reporting
#'
#' @examplesShinylive
#' library(teal.modules.general)
#' interactive <- function() TRUE
Expand Down Expand Up @@ -285,9 +287,6 @@ ui_a_regression <- function(id, ...) {
tags$div(verbatimTextOutput(ns("text")))
)),
encoding = tags$div(
### Reporter
teal.reporter::simple_reporter_ui(ns("simple_reporter")),
###
tags$label("Encodings", class = "text-primary"), tags$br(),
teal.transform::datanames_input(args[c("response", "regressor")]),
teal.transform::data_extract_ui(
Expand Down Expand Up @@ -386,17 +385,13 @@ ui_a_regression <- function(id, ...) {
# Server function for the regression module
srv_a_regression <- function(id,
data,
reporter,
filter_panel_api,
response,
regressor,
plot_height,
plot_width,
ggplot2_args,
default_outlier_label,
decorators) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
Expand Down Expand Up @@ -462,9 +457,11 @@ srv_a_regression <- function(id,
)
})

qenv <- reactive(
teal.code::eval_code(data(), 'library("ggplot2");library("dplyr")') # nolint quotes
)
qenv <- reactive({
obj <- data()
teal.reporter::teal_card(obj) <- append(teal.reporter::teal_card(obj), "# Linear Regression Plot", after = 0)
teal.code::eval_code(obj, 'library("ggplot2");library("dplyr")') # nolint quotes
})

anl_merged_q <- reactive({
req(anl_merged_input())
Expand Down Expand Up @@ -526,7 +523,7 @@ srv_a_regression <- function(id,
)
}

anl_merged_q() %>%
anl_fit <- anl_merged_q() %>%
teal.code::eval_code(substitute(fit <- stats::lm(form, data = ANL), env = list(form = form))) %>%
teal.code::eval_code(quote({
for (regressor in names(fit$contrasts)) {
Expand All @@ -536,7 +533,12 @@ srv_a_regression <- function(id,
)
}
})) %>%
teal.code::eval_code(quote(summary(fit)))
teal.code::eval_code(quote({
fit_summary <- summary(fit)
fit_summary
}))
teal.reporter::teal_card(anl_fit) <- append(teal.reporter::teal_card(anl_fit), "## Plot")
anl_fit
})

label_col <- reactive({
Expand Down Expand Up @@ -982,7 +984,7 @@ srv_a_regression <- function(id,

output_q <- reactive({
teal::validate_inputs(iv_r())
switch(input$plot_type,
obj <- switch(input$plot_type,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Result will be the switch, why use obj?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, instead of

      obj <- switch(input$plot_type,
        "Response vs Regressor" = output_plot_0(),
        "Residuals vs Fitted" = output_plot_1(),
        "Normal Q-Q" = output_plot_2(),
        "Scale-Location" = output_plot_3(),
        "Cook's distance" = output_plot_4(),
        "Residuals vs Leverage" = output_plot_5(),
        "Cook's dist vs Leverage" = output_plot_6()
      )
      obj

we can go with

      switch(input$plot_type,
        "Response vs Regressor" = output_plot_0(),
        "Residuals vs Fitted" = output_plot_1(),
        "Normal Q-Q" = output_plot_2(),
        "Scale-Location" = output_plot_3(),
        "Cook's distance" = output_plot_4(),
        "Residuals vs Leverage" = output_plot_5(),
        "Cook's dist vs Leverage" = output_plot_6()
      )

"Response vs Regressor" = output_plot_0(),
"Residuals vs Fitted" = output_plot_1(),
"Normal Q-Q" = output_plot_2(),
Expand All @@ -991,21 +993,22 @@ srv_a_regression <- function(id,
"Residuals vs Leverage" = output_plot_5(),
"Cook's dist vs Leverage" = output_plot_6()
)
obj
})

decorated_output_q <- srv_decorate_teal_data(
"decorator",
data = output_q,
decorators = select_decorators(decorators, "plot"),
expr = plot
expr = quote(plot)
)

fitted <- reactive({
req(output_q())
req(decorated_output_q())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

❤️ good catch on both of these

decorated_output_q()[["fit"]]
})
plot_r <- reactive({
req(output_q())
req(decorated_output_q())
decorated_output_q()[["plot"]]
})

Expand All @@ -1032,26 +1035,6 @@ srv_a_regression <- function(id,
title = "R code for the regression plot",
)

### REPORTER
if (with_reporter) {
card_fun <- function(comment, label) {
card <- teal::report_card_template(
title = "Linear Regression Plot",
label = label,
with_filter = with_filter,
filter_panel_api = filter_panel_api
)
card$append_text("Plot", "header3")
card$append_plot(plot_r(), dim = pws$dim())
if (!comment == "") {
card$append_text("Comment", "header3")
card$append_text(comment)
}
card$append_src(source_code_r())
card
}
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
}
###
decorated_output_q
})
}
Loading
Loading