Skip to content

POC Redesign of teal.reporter #862

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

Draft
wants to merge 48 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
99a39ee
feat: use bslib tooltip instead of custom css class
vedhav Oct 3, 2024
c675cad
Merge branch 'main' into test@bslib@main
vedhav Dec 11, 2024
6ff4b35
Merge branch 'main' into test@bslib@main
vedhav Feb 13, 2025
f1403d6
specify dependencies branches
m7pr Feb 24, 2025
d44a257
initial test for tm_a_regression
m7pr Feb 24, 2025
3538a2c
update branch name
m7pr Feb 24, 2025
88e6ee4
[skip style] [skip vbump] Restyle files
github-actions[bot] Feb 24, 2025
d735da6
Merge branch 'main' into test@bslib@main
vedhav Feb 25, 2025
f5d3f32
bring back reporter parameter for now
m7pr Feb 25, 2025
ee7b205
Merge branch 'report_redesign_poc@main' of https://github.com/insight…
m7pr Feb 25, 2025
e2216ee
remove function from card_fun in regression
m7pr Feb 26, 2025
928e898
Merge branch 'main' into report_redesign_poc@main
m7pr Feb 26, 2025
809654f
update Remotes
m7pr Feb 26, 2025
5988d34
Merge branch 'report_redesign_poc@main' of https://github.com/insight…
m7pr Feb 26, 2025
a8fec54
return plot and the source code through card_fun
m7pr Feb 26, 2025
3646524
specify dev versions + add Remotes for teal.widgets
m7pr Feb 26, 2025
51d71b5
return elements as rmarkdown
m7pr Mar 3, 2025
1f68993
leave just R objects, let markdown formating be done in teal
m7pr Mar 4, 2025
d0865d1
merge
m7pr Mar 6, 2025
0b0f650
fix: update variable browser based on the new UI changes
vedhav Mar 6, 2025
b25eaee
Merge branch 'main' into test@bslib@main
vedhav Mar 6, 2025
0a3a8d1
merge
m7pr Mar 6, 2025
a4ee004
feat: ui changes
vedhav Mar 6, 2025
439bbc8
fix ci
vedhav Mar 6, 2025
2423239
fix: replace deprecated function calls with bslib calls
vedhav Mar 7, 2025
a61d664
test: fix e2e tests
vedhav Mar 7, 2025
21e6477
chore: remove explicit return
vedhav Mar 7, 2025
71feb58
Merge branch 'test@bslib@main' into report_redesign_poc@main
m7pr Mar 9, 2025
e804ca5
use teal.reporter::code_chunk
m7pr Mar 9, 2025
c62e0bb
Merge branch 'report_redesign_poc@main' of https://github.com/insight…
m7pr Mar 9, 2025
82d5811
Merge branch 'main' into report_redesign_poc@main
m7pr Mar 13, 2025
9c16a21
divide the code into sections, related to the process flow
m7pr Mar 14, 2025
ea33026
link objects in tmg
m7pr Mar 17, 2025
a508a36
reshape pca to report_document
m7pr Mar 17, 2025
11804a2
add rtables for testing to tmg
m7pr Mar 17, 2025
3d94b0b
add libraries code and the code to create objects
m7pr Mar 24, 2025
c1abab4
divide the code using labels
m7pr Mar 27, 2025
77cc108
example with keep_in_report()
m7pr Mar 28, 2025
16a5715
example on how to remove things from report but keep in output
m7pr Mar 28, 2025
307baa1
pull_code function
m7pr Mar 31, 2025
d9cfc2d
typo
m7pr Mar 31, 2025
37b096d
cleanup tm_a_regression code extraction
m7pr Apr 2, 2025
f7f597d
use code labeling and pull_code in pca module
m7pr Apr 2, 2025
da18867
cleanup
m7pr Apr 2, 2025
93567de
adjust tm_g_scatterplot module
m7pr Apr 2, 2025
2f25906
remove reporter argument from new modules
m7pr Apr 25, 2025
2aaadcb
remove pull_code
m7pr Apr 25, 2025
7c6ce30
Merge branch 'main' into report_redesign_poc@main
m7pr Apr 25, 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
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ VignetteBuilder:
knitr,
rmarkdown
Remotes:
insightsengineering/teal.reporter@main,
insightsengineering/teal.code@redesign@main,
insightsengineering/teal.reporter@redesign@main,
insightsengineering/teal.widgets@main,
insightsengineering/teal@main
insightsengineering/teal@redesign@main
Config/Needs/verdepcheck: haleyjeppson/ggmosaic, tidyverse/ggplot2,
rstudio/shiny, insightsengineering/teal,
insightsengineering/teal.slice, insightsengineering/teal.transform,
Expand Down
136 changes: 78 additions & 58 deletions R/tm_a_pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,6 @@ ui_a_pca <- function(id, ...) {
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,8 +350,7 @@ ui_a_pca <- function(id, ...) {
}

# 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")
srv_a_pca <- function(id, data, filter_panel_api, dat, plot_height, plot_width, ggplot2_args, decorators) {
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
Expand Down Expand Up @@ -436,13 +432,15 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
selector_list = selector_list,
datasets = data
)

qenv <- reactive(
teal.code::eval_code(data(), 'library("ggplot2");library("dplyr");library("tidyr")') # nolint quotes
teal.code::eval_code(data(), 'library("ggplot2");library("dplyr");library("tidyr")', label = "libraries") # nolint quotes
)

anl_merged_q <- reactive({
req(anl_merged_input())
qenv() %>%
teal.code::eval_code(as.expression(anl_merged_input()$expr))
teal.code::eval_code(as.expression(anl_merged_input()$expr), label = "data preparations")
})

merged <- list(
Expand Down Expand Up @@ -496,38 +494,39 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
substitute(
expr = keep_columns <- keep_cols,
env = list(keep_cols = keep_cols)
)
),
label = "computation model"
)

if (na_action == "drop") {
qenv <- teal.code::eval_code(
qenv,
quote(ANL <- tidyr::drop_na(ANL, keep_columns))
quote(ANL <- tidyr::drop_na(ANL, keep_columns)),
label = "computation model"
)
}

qenv <- teal.code::eval_code(
teal.code::eval_code(
qenv,
substitute(
expr = pca <- summary(stats::prcomp(ANL[keep_columns], center = center, scale. = scale, retx = TRUE)),
env = list(center = center, scale = scale)
)
)

qenv <- teal.code::eval_code(
qenv,
),
label = "computation model"
) %>%
teal.code::eval_code(
quote({
tbl_importance <- dplyr::as_tibble(pca$importance, rownames = "Metric")
tbl_importance
})
)

}),
label = "computation tbl imp"
) %>%
teal.code::eval_code(
qenv,
quote({
tbl_eigenvector <- dplyr::as_tibble(pca$rotation, rownames = "Variable")
tbl_eigenvector
})
}),
label = "computation tbl eig"
)
})

Expand Down Expand Up @@ -641,7 +640,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
labs = parsed_ggplot2_args$labs,
themes = parsed_ggplot2_args$theme
)
)
),
label = "plot"
)
}

Expand Down Expand Up @@ -713,7 +713,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
labs = `if`(is.null(parsed_ggplot2_args$labs), quote(labs()), parsed_ggplot2_args$labs),
themes = parsed_ggplot2_args$theme
)
)
),
label = "plot"
)
}

Expand Down Expand Up @@ -742,7 +743,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
substitute(
expr = pca_rot <- dplyr::as_tibble(pca$x[, c(x_axis, y_axis)]),
env = list(x_axis = x_axis, y_axis = y_axis)
)
),
label = "plot"
)

# rot_vars = data frame that displays arrows in the plot, need to be scaled to data
Expand All @@ -759,7 +761,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
dplyr::mutate_at(vars(c(x_axis, y_axis)), function(x) r * x / sqrt(max(v_scale)))
},
env = list(x_axis = x_axis, y_axis = y_axis)
)
),
label = "plot"
) %>%
teal.code::eval_code(
if (is.logical(pca$center) && !pca$center) {
Expand All @@ -778,13 +781,15 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
)
} else {
quote(rot_vars <- rot_vars %>% dplyr::mutate(xstart = 0, ystart = 0))
}
},
label = "plot"
) %>%
teal.code::eval_code(
substitute(
expr = rot_vars <- rot_vars %>% dplyr::filter(label %in% variables),
env = list(variables = variables)
)
),
label = "plot"
)
}

Expand Down Expand Up @@ -813,7 +818,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl

qenv <- teal.code::eval_code(
qenv,
substitute(response <- ANL[[resp_col]], env = list(resp_col = resp_col))
substitute(response <- ANL[[resp_col]], env = list(resp_col = resp_col)),
label = "plot"
)

dev_labs <- list(color = varname_w_label(resp_col, ANL))
Expand All @@ -826,13 +832,15 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
) {
qenv <- teal.code::eval_code(
qenv,
quote(pca_rot$response <- as.factor(response))
quote(pca_rot$response <- as.factor(response)),
label = "plot"
)
quote(ggplot2::scale_color_brewer(palette = "Dark2"))
} else if (inherits(response, "Date")) {
qenv <- teal.code::eval_code(
qenv,
quote(pca_rot$response <- numeric(response))
quote(pca_rot$response <- numeric(response)),
label = "plot"
)

quote(
Expand All @@ -845,7 +853,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
} else {
qenv <- teal.code::eval_code(
qenv,
quote(pca_rot$response <- response)
quote(pca_rot$response <- response),
label = "plot"
)
quote(ggplot2::scale_color_gradient(
low = c(getOption("ggplot2.discrete.colour")[2], "darkred")[1],
Expand Down Expand Up @@ -931,7 +940,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
env = list(
plot_call = Reduce(function(x, y) call("+", x, y), pca_plot_biplot_expr)
)
)
),
label = "plot"
)
}

Expand Down Expand Up @@ -1009,7 +1019,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
pc = pc,
plot_call = Reduce(function(x, y) call("+", x, y), ggplot_exprs)
)
)
),
label = "plot"
)
}

Expand Down Expand Up @@ -1040,7 +1051,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
expr = reactive({
substitute(print(.plot), env = list(.plot = as.name(obj_name)))
}),
expr_is_reactive = TRUE
expr_is_reactive = TRUE,
label = "plot"
)
},
names(output_q),
Expand Down Expand Up @@ -1133,30 +1145,38 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
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)
}
###
card_fun <- reactive({
req(data(), decorated_output_q(), plot_r())

teal.reporter::report_document(
"## Setup",
teal.reporter::code_chunk(teal.code::get_code(data())),

"## Libraries",
teal.reporter::code_chunk(teal.code::get_code(decorated_output_q(), label = "libraries"), eval = TRUE),

"## Data Preparations",
teal.reporter::code_chunk(teal.code::get_code(decorated_output_q(), label = "data preparations")),

"## PCA Model",
teal.reporter::code_chunk(teal.code::get_code(decorated_output_q(), label = "computation model")),

"### Principal Components Table",
teal.reporter::code_chunk(teal.code::get_code(decorated_output_q(), label = "computation tbl imp")),
decorated_output_q()[["tbl_importance"]],

"### Eigenvectors Table",
teal.reporter::code_chunk(teal.code::get_code(decorated_output_q(), label = "computation tbl eig")),
decorated_output_q()[["tbl_eigenvector"]],

"## PCA Plot",
teal.reporter::code_chunk(teal.code::get_code(decorated_output_q(), label = "plot")),
plot_r()
)
})

list(
report_card = card_fun
)
})
}
Loading