4747# ' To learn more please refer to the vignette
4848# ' `vignette("transform-module-output", package = "teal")` or the [`teal::teal_transform_module()`] documentation.
4949# '
50+ # ' @inheritSection teal::example_module Reporting
51+ # '
5052# ' @examplesShinylive
5153# ' library(teal.modules.general)
5254# ' interactive <- function() TRUE
@@ -234,10 +236,6 @@ ui_a_pca <- function(id, ...) {
234236 uiOutput(ns(" all_plots" ))
235237 ),
236238 encoding = tags $ div(
237- # ## Reporter
238- teal.reporter :: add_card_button_ui(ns(" add_reporter" ), label = " Add Report Card" ),
239- tags $ br(), tags $ br(),
240- # ##
241239 tags $ label(" Encodings" , class = " text-primary" ),
242240 teal.transform :: datanames_input(args [" dat" ]),
243241 teal.transform :: data_extract_ui(
@@ -353,9 +351,7 @@ ui_a_pca <- function(id, ...) {
353351}
354352
355353# Server function for the PCA module
356- srv_a_pca <- function (id , data , reporter , filter_panel_api , dat , plot_height , plot_width , ggplot2_args , decorators ) {
357- with_reporter <- ! missing(reporter ) && inherits(reporter , " Reporter" )
358- with_filter <- ! missing(filter_panel_api ) && inherits(filter_panel_api , " FilterPanelAPI" )
354+ srv_a_pca <- function (id , data , dat , plot_height , plot_width , ggplot2_args , decorators ) {
359355 checkmate :: assert_class(data , " reactive" )
360356 checkmate :: assert_class(isolate(data()), " teal_data" )
361357 moduleServer(id , function (input , output , session ) {
@@ -436,9 +432,16 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
436432 selector_list = selector_list ,
437433 datasets = data
438434 )
439- qenv <- reactive(
440- teal.code :: eval_code(data(), ' library("ggplot2");library("dplyr");library("tidyr")' ) # nolint quotes
441- )
435+ qenv <- reactive({
436+ obj <- data()
437+ teal.reporter :: teal_card(obj ) <-
438+ c(
439+ teal.reporter :: teal_card(" # Principal Component Analysis" ),
440+ teal.reporter :: teal_card(obj ),
441+ teal.reporter :: teal_card(" ## Module's code" )
442+ )
443+ teal.code :: eval_code(obj , ' library("ggplot2");library("dplyr");library("tidyr")' ) # nolint: quotes
444+ })
442445 anl_merged_q <- reactive({
443446 req(anl_merged_input())
444447 qenv() %> %
@@ -514,6 +517,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
514517 )
515518 )
516519
520+ teal.reporter :: teal_card(qenv ) <- c(teal.reporter :: teal_card(qenv ), " ## Principal Components Table" )
521+
517522 qenv <- teal.code :: eval_code(
518523 qenv ,
519524 quote({
@@ -522,6 +527,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
522527 })
523528 )
524529
530+ teal.reporter :: teal_card(qenv ) <- c(teal.reporter :: teal_card(qenv ), " ## Eigenvectors Table" )
531+
525532 teal.code :: eval_code(
526533 qenv ,
527534 quote({
@@ -602,7 +609,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
602609 ),
603610 ggtheme = ggtheme
604611 )
605-
612+ teal.reporter :: teal_card( base_q ) <- c( teal.reporter :: teal_card( base_q ), " ## Elbow plot " )
606613 teal.code :: eval_code(
607614 base_q ,
608615 substitute(
@@ -679,6 +686,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
679686 ggtheme = ggtheme
680687 )
681688
689+ teal.reporter :: teal_card(base_q ) <- c(teal.reporter :: teal_card(base_q ), " ## Circle plot" )
682690 teal.code :: eval_code(
683691 base_q ,
684692 substitute(
@@ -737,6 +745,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
737745 size <- input $ size
738746 font_size <- input $ font_size
739747
748+ teal.reporter :: teal_card(base_q ) <- c(teal.reporter :: teal_card(base_q ), " ## Biplot" )
740749 qenv <- teal.code :: eval_code(
741750 qenv ,
742751 substitute(
@@ -997,6 +1006,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
9971006 parsed_ggplot2_args $ theme
9981007 )
9991008
1009+ teal.reporter :: teal_card(base_q ) <- c(teal.reporter :: teal_card(base_q ), " ## Eigenvector plot" )
10001010 teal.code :: eval_code(
10011011 base_q ,
10021012 substitute(
@@ -1038,9 +1048,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
10381048 data = q ,
10391049 decorators = select_decorators(decorators , obj_name ),
10401050 expr = reactive({
1041- substitute(print(.plot ), env = list (.plot = as.name(obj_name )))
1042- }),
1043- expr_is_reactive = TRUE
1051+ substitute(.plot , env = list (.plot = as.name(obj_name )))
1052+ })
10441053 )
10451054 },
10461055 names(output_q ),
@@ -1071,6 +1080,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
10711080 graph_align = " center"
10721081 )
10731082
1083+ decorated_output_dims_q <- set_chunk_dims(pws , decorated_output_q )
1084+
10741085 # tables ----
10751086 output $ tbl_importance <- renderTable(
10761087 expr = {
@@ -1132,31 +1143,6 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
11321143 verbatim_content = source_code_r ,
11331144 title = " R Code for PCA"
11341145 )
1135-
1136- # ## REPORTER
1137- if (with_reporter ) {
1138- card_fun <- function (comment , label ) {
1139- card <- teal :: report_card_template(
1140- title = " Principal Component Analysis Plot" ,
1141- label = label ,
1142- with_filter = with_filter ,
1143- filter_panel_api = filter_panel_api
1144- )
1145- card $ append_text(" Principal Components Table" , " header3" )
1146- card $ append_table(computation()[[" tbl_importance" ]])
1147- card $ append_text(" Eigenvectors Table" , " header3" )
1148- card $ append_table(computation()[[" tbl_eigenvector" ]])
1149- card $ append_text(" Plot" , " header3" )
1150- card $ append_plot(plot_r(), dim = pws $ dim())
1151- if (! comment == " " ) {
1152- card $ append_text(" Comment" , " header3" )
1153- card $ append_text(comment )
1154- }
1155- card $ append_src(source_code_r())
1156- card
1157- }
1158- teal.reporter :: add_card_button_srv(" add_reporter" , reporter = reporter , card_fun = card_fun )
1159- }
1160- # ##
1146+ decorated_output_dims_q
11611147 })
11621148}
0 commit comments