1111# ' Specifies variable(s) to be analyzed for outliers.
1212# ' @param categorical_var (`data_extract_spec` or `list` of multiple `data_extract_spec`) optional,
1313# ' specifies the categorical variable(s) to split the selected outlier variables on.
14- # ' @param table_decorator (`list` of `teal_transform_module`) optional,
15- # ' decorator for the table.
16- # ' @param boxplot_decorator (`list` of `teal_transform_module`) optional,
17- # ' decorator for the box plot.
18- # ' @param violin_decorator (`list` of `teal_transform_module`) optional,
19- # ' decorator for the violin plot.
20- # ' @param density_decorator (`list` of `teal_transform_module`) optional,
21- # ' decorator for the density plot.
22- # ' @param cum_dist_decorator (`list` of `teal_transform_module`) optional,
23- # ' decorator for the cumulative distribution plot.
2414# '
2515# ' @templateVar ggnames "Boxplot","Density Plot","Cumulative Distribution Plot"
2616# ' @template ggplot2_args_multi
2717# '
2818# ' @inherit shared_params return
2919# '
30- # ' @section Decorating `tm_outliers`:
31- # '
32- # ' This module generates the following objects, which can be modified in place using decorators:
33- # ' - `table` (`data.frame`)
34- # ' - `plot` (`ggplot2`)
35- # '
36- # ' For additional details and examples of decorators, refer to the vignette
37- # ' `vignette("decorate-modules-output", package = "teal")` or the [`teal_transform_module()`] documentation.
38- # '
3920# ' @examplesShinylive
4021# ' library(teal.modules.general)
4122# ' interactive <- function() TRUE
4223# ' {{ next_example }}
4324# ' @examples
44- # '
4525# ' # general data example
4626# ' data <- teal_data()
4727# ' data <- within(data, {
9171# ' interactive <- function() TRUE
9272# ' {{ next_example }}
9373# ' @examples
94- # '
9574# ' # CDISC data example
9675# ' data <- teal_data()
9776# ' data <- within(data, {
10281# ' fact_vars_adsl <- names(Filter(isTRUE, sapply(data[["ADSL"]], is.factor)))
10382# ' vars <- choices_selected(variable_choices(data[["ADSL"]], fact_vars_adsl))
10483# '
105- # '
106- # '
10784# ' app <- init(
10885# ' data = data,
10986# ' modules = modules(
@@ -148,12 +125,7 @@ tm_outliers <- function(label = "Outliers Module",
148125 plot_height = c(600 , 200 , 2000 ),
149126 plot_width = NULL ,
150127 pre_output = NULL ,
151- post_output = NULL ,
152- table_decorator = teal_transform_module(),
153- boxplot_decorator = teal_transform_module(),
154- violin_decorator = teal_transform_module(),
155- density_decorator = teal_transform_module(),
156- cum_dist_decorator = teal_transform_module()) {
128+ post_output = NULL ) {
157129 message(" Initializing tm_outliers" )
158130
159131 # Normalize the parameters
@@ -200,19 +172,15 @@ tm_outliers <- function(label = "Outliers Module",
200172 categorical_var = categorical_var
201173 )
202174
203-
204175 ans <- module(
205176 label = label ,
206177 server = srv_outliers ,
207178 server_args = c(
208179 data_extract_list ,
209- list (
210- plot_height = plot_height , plot_width = plot_width , ggplot2_args = ggplot2_args ,
211- decorators = list (table = table_decorator , boxplot = boxplot_decorator , violin = violin_decorator , density = density_decorator , cum_dist = cum_dist_decorator )
212- )
180+ list (plot_height = plot_height , plot_width = plot_width , ggplot2_args = ggplot2_args )
213181 ),
214182 ui = ui_outliers ,
215- ui_args = c( args ) ,
183+ ui_args = args ,
216184 datanames = teal.transform :: get_extract_datanames(data_extract_list )
217185 )
218186 attr(ans , " teal_bookmarkable" ) <- TRUE
@@ -229,31 +197,20 @@ ui_outliers <- function(id, ...) {
229197 output = teal.widgets :: white_small_well(
230198 uiOutput(ns(" total_outliers" )),
231199 DT :: dataTableOutput(ns(" summary_table" )),
232- ui_teal_transform_data(ns(" table_decorator" ), args $ table_decorator ),
233200 uiOutput(ns(" total_missing" )),
234201 tags $ br(), tags $ hr(),
235202 tabsetPanel(
236203 id = ns(" tabs" ),
237204 tabPanel(
238205 " Boxplot" ,
239- conditionalPanel(
240- condition = sprintf(" input['%s'] == 'Box plot'" , ns(" boxplot_alts" )),
241- ui_teal_transform_data(ns(" boxplot_decorator" ), args $ boxplot_decorator )
242- ),
243- conditionalPanel(
244- condition = sprintf(" input['%s'] == 'Violin plot'" , ns(" boxplot_alts" )),
245- ui_teal_transform_data(ns(" violin_decorator" ), args $ violin_decorator )
246- ),
247206 teal.widgets :: plot_with_settings_ui(id = ns(" box_plot" ))
248207 ),
249208 tabPanel(
250209 " Density Plot" ,
251- ui_teal_transform_data(ns(" density_decorator" ), args $ density_decorator ),
252210 teal.widgets :: plot_with_settings_ui(id = ns(" density_plot" ))
253211 ),
254212 tabPanel(
255213 " Cumulative Distribution Plot" ,
256- ui_teal_transform_data(ns(" cum_dist_decorator" ), args $ cum_dist_decorator ),
257214 teal.widgets :: plot_with_settings_ui(id = ns(" cum_density_plot" ))
258215 )
259216 ),
@@ -362,10 +319,9 @@ ui_outliers <- function(id, ...) {
362319 )
363320}
364321
365- # Server function for the outliers module
366322# Server function for the outliers module
367323srv_outliers <- function (id , data , reporter , filter_panel_api , outlier_var ,
368- categorical_var , plot_height , plot_width , ggplot2_args , decorators ) {
324+ categorical_var , plot_height , plot_width , ggplot2_args ) {
369325 with_reporter <- ! missing(reporter ) && inherits(reporter , " Reporter" )
370326 with_filter <- ! missing(filter_panel_api ) && inherits(filter_panel_api , " FilterPanelAPI" )
371327 checkmate :: assert_class(data , " reactive" )
@@ -805,7 +761,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
805761 teal.code :: eval_code(
806762 common_code_q(),
807763 substitute(
808- expr = plot <- plot_call +
764+ expr = g <- plot_call +
809765 scale_color_manual(values = c(" TRUE" = " red" , " FALSE" = " black" )) +
810766 labs + ggthemes + themes ,
811767 env = list (
@@ -815,7 +771,8 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
815771 themes = parsed_ggplot2_args $ theme
816772 )
817773 )
818- )
774+ ) %> %
775+ teal.code :: eval_code(quote(print(g )))
819776 })
820777
821778 # density plot
@@ -866,15 +823,16 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
866823 teal.code :: eval_code(
867824 common_code_q(),
868825 substitute(
869- expr = plot <- plot_call + labs + ggthemes + themes ,
826+ expr = g <- plot_call + labs + ggthemes + themes ,
870827 env = list (
871828 plot_call = plot_call ,
872829 labs = parsed_ggplot2_args $ labs ,
873830 themes = parsed_ggplot2_args $ theme ,
874831 ggthemes = parsed_ggplot2_args $ ggtheme
875832 )
876833 )
877- )
834+ ) %> %
835+ teal.code :: eval_code(quote(print(g )))
878836 })
879837
880838 # Cumulative distribution plot
@@ -967,7 +925,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
967925 teal.code :: eval_code(
968926 qenv ,
969927 substitute(
970- expr = plot <- plot_call +
928+ expr = g <- plot_call +
971929 geom_point(data = outlier_points , aes(x = outlier_var_name , y = y , color = is_outlier_selected )) +
972930 scale_color_manual(values = c(" TRUE" = " red" , " FALSE" = " black" )) +
973931 labs + ggthemes + themes ,
@@ -979,24 +937,19 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
979937 ggthemes = parsed_ggplot2_args $ ggtheme
980938 )
981939 )
982- )
940+ ) %> %
941+ teal.code :: eval_code(quote(print(g )))
983942 })
984943
985- decorated_boxplot_q <- srv_teal_transform_data(" boxplot_decorator" , data = boxplot_q , transformators = decorators $ boxplot )
986- decorated_violin_q <- srv_teal_transform_data(" violin_decorator" , data = boxplot_q , transformators = decorators $ violin )
987- # TODO decorated_violin_q is not used anywhere
988- decorated_density_plot_q <- srv_teal_transform_data(" density_decorator" , data = density_plot_q , transformators = decorators $ density )
989- decorated_cumulative_plot_q <- srv_teal_transform_data(" cum_dist_decorator" , data = cumulative_plot_q , transformators = decorators $ cum_dist )
990-
991944 final_q <- reactive({
992945 req(input $ tabs )
993946 tab_type <- input $ tabs
994947 result_q <- if (tab_type == " Boxplot" ) {
995- decorated_boxplot_q ()
948+ boxplot_q ()
996949 } else if (tab_type == " Density Plot" ) {
997- decorated_density_plot_q ()
950+ density_plot_q ()
998951 } else if (tab_type == " Cumulative Distribution Plot" ) {
999- decorated_cumulative_plot_q ()
952+ cumulative_plot_q ()
1000953 }
1001954 # used to display table when running show-r-code code
1002955 # added after the plots so that a change in selected columns doesn't affect
@@ -1009,7 +962,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
1009962 setdiff(names(ANL_OUTLIER ), c(" is_outlier_selected" , " order" )),
1010963 table_columns
1011964 )
1012- table <- ANL_OUTLIER_EXTENDED [ANL_OUTLIER_EXTENDED $ is_outlier_selected , columns_index ]
965+ ANL_OUTLIER_EXTENDED [ANL_OUTLIER_EXTENDED $ is_outlier_selected , columns_index ]
1013966 },
1014967 env = list (
1015968 table_columns = input $ table_ui_columns
@@ -1018,11 +971,6 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
1018971 )
1019972 })
1020973
1021-
1022- decorated_final_q <-
1023- srv_teal_transform_data(" cum_dist_decorator" , data = final_q , transformators = decorators $ table_decorator )
1024- # TODO: reuse decorated_final_q in table generation
1025-
1026974 # slider text
1027975 output $ ui_outlier_help <- renderUI({
1028976 req(input $ method )
@@ -1073,15 +1021,15 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
10731021
10741022 boxplot_r <- reactive({
10751023 teal :: validate_inputs(iv_r())
1076- decorated_boxplot_q ()[[" plot " ]]
1024+ boxplot_q ()[[" g " ]]
10771025 })
10781026 density_plot_r <- reactive({
10791027 teal :: validate_inputs(iv_r())
1080- decorated_density_plot_q ()[[" plot " ]]
1028+ density_plot_q ()[[" g " ]]
10811029 })
10821030 cumulative_plot_r <- reactive({
10831031 teal :: validate_inputs(iv_r())
1084- decorated_cumulative_plot_q ()[[" plot " ]]
1032+ cumulative_plot_q ()[[" g " ]]
10851033 })
10861034
10871035 box_pws <- teal.widgets :: plot_with_settings_srv(
@@ -1269,7 +1217,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
12691217
12701218 teal.widgets :: verbatim_popup_srv(
12711219 id = " rcode" ,
1272- verbatim_content = reactive(teal.code :: get_code(req( final_q() ))),
1220+ verbatim_content = reactive(teal.code :: get_code(final_q())),
12731221 title = " Show R Code for Outlier"
12741222 )
12751223
@@ -1301,7 +1249,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
13011249 card $ append_text(" Comment" , " header3" )
13021250 card $ append_text(comment )
13031251 }
1304- card $ append_src(teal.code :: get_code(req( final_q() )))
1252+ card $ append_src(teal.code :: get_code(final_q()))
13051253 card
13061254 }
13071255 teal.reporter :: simple_reporter_srv(" simple_reporter" , reporter = reporter , card_fun = card_fun )
0 commit comments