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 11 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
7 changes: 4 additions & 3 deletions R/tm_a_pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -1038,9 +1038,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
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 @@ -1158,5 +1157,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
}
###

decorated_output_q
})
}
19 changes: 12 additions & 7 deletions R/tm_a_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,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) <- c(teal.reporter::teal_card(obj), "# Module's computation")
teal.code::eval_code(obj, 'library("ggplot2");library("dplyr")') # nolint quotes
})

anl_merged_q <- reactive({
req(anl_merged_input())
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 = print(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 Down Expand Up @@ -1055,5 +1058,7 @@ srv_a_regression <- function(id,
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
}
###

decorated_output_q
})
}
13 changes: 5 additions & 8 deletions R/tm_g_association.R
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ srv_tm_g_association <- function(id,
)

qenv <- reactive(
teal.code::eval_code(data(), 'library("ggplot2");library("dplyr");library("tern");library("ggmosaic")') # nolint quotes
teal.code::eval_code(data(), 'library("ggplot2");library("dplyr");library("ggmosaic")') # nolint quotes
)
anl_merged_q <- reactive({
req(anl_merged_input())
Expand Down Expand Up @@ -506,9 +506,7 @@ srv_tm_g_association <- function(id,
substitute(
expr = {
plots <- plot_calls
plot_top <- plots[[1]]
plot_bottom <- plots[[2]]
plot <- tern::stack_grobs(grobs = lapply(list(plot_top, plot_bottom), ggplot2::ggplotGrob))
plot <- grid.arrange(plots[[1]], plots[[2]], ncol = 1)
},
env = list(
plot_calls = do.call(
Expand All @@ -525,10 +523,7 @@ srv_tm_g_association <- function(id,
id = "decorator",
data = output_q,
decorators = select_decorators(decorators, "plot"),
expr = {
grid::grid.newpage()
grid::grid.draw(plot)
}
expr = quote(plot)
)

plot_r <- reactive({
Expand Down Expand Up @@ -576,6 +571,8 @@ srv_tm_g_association <- function(id,
}
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
}

decorated_output_grob_q
###
})
}
7 changes: 4 additions & 3 deletions R/tm_g_bivariate.R
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ srv_g_bivariate <- function(id,
without_facet <- (is.null(nulled_row_facet_name) && is.null(nulled_col_facet_name)) || !facetting

print_call <- if (without_facet) {
quote(print(plot))
quote(plot)
} else {
substitute(
expr = {
Expand All @@ -730,8 +730,7 @@ srv_g_bivariate <- function(id,
)
}
print_call
}),
expr_is_reactive = TRUE
})
)

plot_r <- reactive(req(decorated_output_q_facets())[["plot"]])
Expand Down Expand Up @@ -774,6 +773,8 @@ srv_g_bivariate <- function(id,
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
}
###

decorated_output_q_facets
})
}

Expand Down
15 changes: 11 additions & 4 deletions R/tm_g_distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -1297,28 +1297,28 @@ srv_distribution <- function(id,
"d_density",
data = output_dist_q,
decorators = select_decorators(decorators, "histogram_plot"),
expr = print(histogram_plot)
expr = quote(histogram_plot)
)

decorated_output_qq_q <- srv_decorate_teal_data(
"d_qq",
data = output_qq_q,
decorators = select_decorators(decorators, "qq_plot"),
expr = print(qq_plot)
expr = quote(qq_plot)
)

decorated_output_summary_q <- srv_decorate_teal_data(
"d_summary",
data = output_summary_q,
decorators = select_decorators(decorators, "summary_table"),
expr = summary_table
expr = quote(summary_table)
)

decorated_output_test_q <- srv_decorate_teal_data(
"d_test",
data = output_test_q,
decorators = select_decorators(decorators, "test_table"),
expr = test_table
expr = quote(test_table)
)

decorated_output_q <- reactive({
Expand Down Expand Up @@ -1417,5 +1417,12 @@ srv_distribution <- function(id,
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
}
###
reactive(
if (input$tabs == "Histogram") {
decorated_output_dist_q()
} else if (input$tabs == "QQplot") {
decorated_output_qq_q()
}
)
})
}
4 changes: 3 additions & 1 deletion R/tm_g_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ srv_g_response <- function(id,
id = "decorator",
data = output_q,
decorators = select_decorators(decorators, "plot"),
expr = print(plot)
expr = quote(plot)
)

plot_r <- reactive(req(decorated_output_plot_q())[["plot"]])
Expand Down Expand Up @@ -622,5 +622,7 @@ srv_g_response <- function(id,
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
}
###

decorated_output_plot_q
})
}
4 changes: 3 additions & 1 deletion R/tm_g_scatterplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ srv_g_scatterplot <- function(id,
id = "decorator",
data = output_q,
decorators = select_decorators(decorators, "plot"),
expr = print(plot)
expr = quote(plot)
)

plot_r <- reactive(req(decorated_output_plot_q())[["plot"]])
Expand Down Expand Up @@ -1095,5 +1095,7 @@ srv_g_scatterplot <- function(id,
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
}
###

decorated_output_plot_q
})
}
7 changes: 5 additions & 2 deletions R/tm_g_scatterplotmatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ srv_g_scatterplotmatrix <- function(id,

anl_merged_q <- reactive({
req(anl_merged_input())
qenv <- teal.code::eval_code(data(), 'library("dplyr");library("lattice")') # nolint quotes
obj <- data()
teal.reporter::teal_card(obj) <- c(teal.reporter::teal_card(obj), "# Module's computation")
qenv <- teal.code::eval_code(obj, 'library("dplyr");library("lattice")') # nolint: quotes.
teal.code::eval_code(qenv, as.expression(anl_merged_input()$expr))
})

Expand Down Expand Up @@ -464,7 +466,7 @@ srv_g_scatterplotmatrix <- function(id,
id = "decorator",
data = output_q,
decorators = select_decorators(decorators, "plot"),
expr = print(plot)
expr = quote(plot)
)

plot_r <- reactive(req(decorated_output_q())[["plot"]])
Expand Down Expand Up @@ -529,6 +531,7 @@ srv_g_scatterplotmatrix <- function(id,
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
}
###
decorated_output_q
})
}

Expand Down
35 changes: 26 additions & 9 deletions R/tm_missing_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ srv_page_missing_data <- function(id, data, reporter, filter_panel_api, dataname
})
})

lapply(
result <- sapply(
datanames,
function(x) {
srv_missing_data(
Expand All @@ -280,8 +280,18 @@ srv_page_missing_data <- function(id, data, reporter, filter_panel_api, dataname
ggplot2_args = ggplot2_args,
decorators = decorators
)
}
},
USE.NAMES = TRUE,
simplify = FALSE
)

reactive({
if (is.null(input$dataname_tab)) {
teal.data::teal_data()
} else {
result[[input$dataname_tab]]()
}
})
})
}

Expand Down Expand Up @@ -521,7 +531,10 @@ srv_missing_data <- function(id,

group_var <- input$group_by_var
anl <- data_r()
qenv <- teal.code::eval_code(data(), {
obj <- data()
teal.reporter::teal_card(obj) <- c(teal.reporter::teal_card(obj), "# Module's computation")

qenv <- teal.code::eval_code(obj, {
'library("dplyr");library("ggplot2");library("tidyr");library("gridExtra")' # nolint quotes
})

Expand Down Expand Up @@ -1269,34 +1282,36 @@ srv_missing_data <- function(id,
id = "dec_summary_plot",
data = summary_plot_q,
decorators = select_decorators(decorators, "summary_plot"),
expr = {
expr = quote({
grid::grid.newpage()
grid::grid.draw(summary_plot)
}
summary_plot
})
)

decorated_combination_plot_q <- srv_decorate_teal_data(
id = "dec_combination_plot",
data = combination_plot_q,
decorators = select_decorators(decorators, "combination_plot"),
expr = {
expr = quote({
grid::grid.newpage()
grid::grid.draw(combination_plot)
}
combination_plot
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TableGrob appears that is not supported by to_rmd in teal.reporter @m7pr @gogonzo do you think we should add it?

Screenshot from report.html

image

})
)

decorated_summary_table_q <- srv_decorate_teal_data(
id = "dec_summary_table",
data = summary_table_q,
decorators = select_decorators(decorators, "table"),
expr = table
expr = quote(table)
)

decorated_by_subject_plot_q <- srv_decorate_teal_data(
id = "dec_by_subject_plot",
data = by_subject_plot_q,
decorators = select_decorators(decorators, "by_subject_plot"),
expr = print(by_subject_plot)
expr = quote(by_subject_plot)
)

# Plots & tables reactives
Expand Down Expand Up @@ -1417,5 +1432,7 @@ srv_missing_data <- function(id,
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
}
###

decorated_final_q
})
}
5 changes: 2 additions & 3 deletions R/tm_outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -1037,8 +1037,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
},
env = list(table_columns = input$table_ui_columns, .plot = as.name(obj_name))
)
}),
expr_is_reactive = TRUE
})
)
},
stats::setNames(nm = c("box_plot", "density_plot", "cumulative_plot")),
Expand All @@ -1051,7 +1050,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
"d_table",
data = decorated_final_q_no_table,
decorators = select_decorators(decorators, "table"),
expr = table
expr = quote(table)
)

output$summary_table <- DT::renderDataTable(
Expand Down
2 changes: 1 addition & 1 deletion R/tm_t_crosstable.R
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ srv_t_crosstable <- function(id, data, reporter, filter_panel_api, label, x, y,
id = "decorator",
data = output_q,
decorators = select_decorators(decorators, "table"),
expr = table
expr = quote(table)
)

output$title <- renderText(req(decorated_output_q())[["title"]])
Expand Down
Loading