2525# ' - `biplot` (`ggplot2`)
2626# ' - `eigenvector_plot` (`ggplot2`)
2727# '
28- # ' Decorators can be applied to all outputs or only to specific objects using a
29- # ' named list of `teal_transform_module` objects.
30- # ' The `"default"` name is reserved for decorators that are applied to all outputs.
28+ # ' A Decorator is applied to the specific output using a named list of `teal_transform_module` objects.
29+ # ' The name of this list corresponds to the name of the output to which the decorator is applied.
3130# ' See code snippet below:
3231# '
3332# ' ```
3433# ' tm_a_pca(
3534# ' ..., # arguments for module
3635# ' decorators = list(
37- # ' default = list(teal_transform_module(...)), # applied to all outputs
38- # ' elbow_plot = list(teal_transform_module(...)), # applied only to `elbow_plot` output
39- # ' circle_plot = list(teal_transform_module(...)) # applied only to `circle_plot` output
40- # ' biplot = list(teal_transform_module(...)) # applied only to `biplot` output
41- # ' eigenvector_plot = list(teal_transform_module(...)) # applied only to `eigenvector_plot` output
36+ # ' elbow_plot = teal_transform_module(...), # applied to the `elbow_plot` output
37+ # ' circle_plot = teal_transform_module(...), # applied to the `circle_plot` output
38+ # ' biplot = teal_transform_module(...), # applied to the `biplot` output
39+ # ' eigenvector_plot = teal_transform_module(...) # applied to the `eigenvector_plot` output
4240# ' )
4341# ' )
4442# ' ```
4543# '
4644# ' For additional details and examples of decorators, refer to the vignette
47- # ' `vignette("decorate-modules -output", package = "teal")` or the [`teal::teal_transform_module()`] documentation.
45+ # ' `vignette("transform-module -output", package = "teal")` or the [`teal::teal_transform_module()`] documentation.
4846# '
4947# ' @examplesShinylive
5048# ' library(teal.modules.general)
@@ -186,9 +184,7 @@ tm_a_pca <- function(label = "Principal Component Analysis",
186184 checkmate :: assert_multi_class(post_output , c(" shiny.tag" , " shiny.tag.list" , " html" ), null.ok = TRUE )
187185
188186 available_decorators <- c(" elbow_plot" , " circle_plot" , " biplot" , " eigenvector_plot" )
189- decorators <- normalize_decorators(decorators )
190187 assert_decorators(decorators , available_decorators )
191- # End of assertions
192188
193189 # Make UI args
194190 args <- as.list(environment())
@@ -438,10 +434,10 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
438434 selector_list = selector_list ,
439435 datasets = data
440436 )
441-
437+ qenv <- teal.code :: eval_code(data(), ' library("ggplot2");library("dplyr");library("tidyr") ' ) # nolint quotes
442438 anl_merged_q <- reactive({
443439 req(anl_merged_input())
444- data() %> %
440+ qenv %> %
445441 teal.code :: eval_code(as.expression(anl_merged_input()$ expr ))
446442 })
447443
@@ -585,12 +581,12 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
585581 theme = list (
586582 legend.position = " right" ,
587583 legend.spacing.y = quote(grid :: unit(- 5 , " pt" )),
588- legend.title = quote(element_text(vjust = 25 )),
584+ legend.title = quote(ggplot2 :: element_text(vjust = 25 )),
589585 axis.text.x = substitute(
590- element_text(angle = angle_value , hjust = hjust_value ),
586+ ggplot2 :: element_text(angle = angle_value , hjust = hjust_value ),
591587 list (angle_value = angle_value , hjust_value = hjust_value )
592588 ),
593- text = substitute(element_text(size = font_size ), list (font_size = font_size ))
589+ text = substitute(ggplot2 :: element_text(size = font_size ), list (font_size = font_size ))
594590 )
595591 )
596592
@@ -615,24 +611,24 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
615611 )
616612
617613 cols <- c(getOption(" ggplot2.discrete.colour" ), c(" lightblue" , " darkred" , " black" ))[1 : 3 ]
618- elbow_plot <- ggplot(mapping = aes_string(x = " component" , y = " value" )) +
619- geom_bar(
620- aes(fill = " Single variance" ),
614+ elbow_plot <- ggplot2 :: ggplot(mapping = ggplot2 :: aes_string(x = " component" , y = " value" )) +
615+ ggplot2 :: geom_bar(
616+ ggplot2 :: aes(fill = " Single variance" ),
621617 data = dplyr :: filter(elb_dat , metric == " Proportion of Variance" ),
622618 color = " black" ,
623619 stat = " identity"
624620 ) +
625- geom_point(
626- aes(color = " Cumulative variance" ),
621+ ggplot2 :: geom_point(
622+ ggplot2 :: aes(color = " Cumulative variance" ),
627623 data = dplyr :: filter(elb_dat , metric == " Cumulative Proportion" )
628624 ) +
629- geom_line(
630- aes(group = 1 , color = " Cumulative variance" ),
625+ ggplot2 :: geom_line(
626+ ggplot2 :: aes(group = 1 , color = " Cumulative variance" ),
631627 data = dplyr :: filter(elb_dat , metric == " Cumulative Proportion" )
632628 ) +
633629 labs +
634- scale_color_manual(values = c(" Cumulative variance" = cols [2 ], " Single variance" = cols [3 ])) +
635- scale_fill_manual(values = c(" Cumulative variance" = cols [2 ], " Single variance" = cols [1 ])) +
630+ ggplot2 :: scale_color_manual(values = c(" Cumulative variance" = cols [2 ], " Single variance" = cols [3 ])) +
631+ ggplot2 :: scale_fill_manual(values = c(" Cumulative variance" = cols [2 ], " Single variance" = cols [1 ])) +
636632 ggthemes +
637633 themes
638634 },
@@ -660,9 +656,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
660656
661657 dev_ggplot2_args <- teal.widgets :: ggplot2_args(
662658 theme = list (
663- text = substitute(element_text(size = font_size ), list (font_size = font_size )),
659+ text = substitute(ggplot2 :: element_text(size = font_size ), list (font_size = font_size )),
664660 axis.text.x = substitute(
665- element_text(angle = angle_val , hjust = hjust_val ),
661+ ggplot2 :: element_text(angle = angle_val , hjust = hjust_val ),
666662 list (angle_val = angle , hjust_val = hjust )
667663 )
668664 )
@@ -692,15 +688,15 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
692688 y = sin(seq(0 , 2 * pi , length.out = 100 ))
693689 )
694690
695- circle_plot <- ggplot(pca_rot ) +
696- geom_point(aes_string(x = x_axis , y = y_axis )) +
697- geom_label(
698- aes_string(x = x_axis , y = y_axis , label = " label" ),
691+ circle_plot <- ggplot2 :: ggplot(pca_rot ) +
692+ ggplot2 :: geom_point(ggplot2 :: aes_string(x = x_axis , y = y_axis )) +
693+ ggplot2 :: geom_label(
694+ ggplot2 :: aes_string(x = x_axis , y = y_axis , label = " label" ),
699695 nudge_x = 0.1 , nudge_y = 0.05 ,
700696 fontface = " bold"
701697 ) +
702- geom_path(aes(x , y , group = 1 ), data = circle_data ) +
703- geom_point(aes(x = x , y = y ), data = data.frame (x = 0 , y = 0 ), shape = " x" , size = 5 ) +
698+ ggplot2 :: geom_path(ggplot2 :: aes(x , y , group = 1 ), data = circle_data ) +
699+ ggplot2 :: geom_point(ggplot2 :: aes(x = x , y = y ), data = data.frame (x = 0 , y = 0 ), shape = " x" , size = 5 ) +
704700 labs +
705701 ggthemes +
706702 themes
@@ -794,7 +790,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
794790 pca_plot_biplot_expr <- c(
795791 pca_plot_biplot_expr ,
796792 substitute(
797- geom_point(aes_string(x = x_axis , y = y_axis ), data = pca_rot , alpha = alpha , size = size ),
793+ ggplot2 :: geom_point(ggplot2 :: aes_string(x = x_axis , y = y_axis ),
794+ data = pca_rot , alpha = alpha , size = size
795+ ),
798796 list (x_axis = input $ x_axis , y_axis = input $ y_axis , alpha = input $ alpha , size = input $ size )
799797 )
800798 )
@@ -805,7 +803,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
805803 response <- ANL [[resp_col ]]
806804
807805 aes_biplot <- substitute(
808- aes_string(x = x_axis , y = y_axis , color = " response" ),
806+ ggplot2 :: aes_string(x = x_axis , y = y_axis , color = " response" ),
809807 env = list (x_axis = x_axis , y_axis = y_axis )
810808 )
811809
@@ -826,15 +824,15 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
826824 qenv ,
827825 quote(pca_rot $ response <- as.factor(response ))
828826 )
829- quote(scale_color_brewer(palette = " Dark2" ))
827+ quote(ggplot2 :: scale_color_brewer(palette = " Dark2" ))
830828 } else if (inherits(response , " Date" )) {
831829 qenv <- teal.code :: eval_code(
832830 qenv ,
833831 quote(pca_rot $ response <- numeric (response ))
834832 )
835833
836834 quote(
837- scale_color_gradient(
835+ ggplot2 :: scale_color_gradient(
838836 low = c(getOption(" ggplot2.discrete.colour" )[2 ], " darkred" )[1 ],
839837 high = c(getOption(" ggplot2.discrete.colour" ), " lightblue" )[1 ],
840838 labels = function (x ) as.Date(x , origin = " 1970-01-01" )
@@ -845,7 +843,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
845843 qenv ,
846844 quote(pca_rot $ response <- response )
847845 )
848- quote(scale_color_gradient(
846+ quote(ggplot2 :: scale_color_gradient(
849847 low = c(getOption(" ggplot2.discrete.colour" )[2 ], " darkred" )[1 ],
850848 high = c(getOption(" ggplot2.discrete.colour" ), " lightblue" )[1 ]
851849 ))
@@ -854,7 +852,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
854852 pca_plot_biplot_expr <- c(
855853 pca_plot_biplot_expr ,
856854 substitute(
857- geom_point(aes_biplot , data = pca_rot , alpha = alpha , size = size ),
855+ ggplot2 :: geom_point(aes_biplot , data = pca_rot , alpha = alpha , size = size ),
858856 env = list (aes_biplot = aes_biplot , alpha = alpha , size = size )
859857 ),
860858 scales_biplot
@@ -865,17 +863,17 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
865863 pca_plot_biplot_expr <- c(
866864 pca_plot_biplot_expr ,
867865 substitute(
868- geom_segment(
869- aes_string(x = " xstart" , y = " ystart" , xend = x_axis , yend = y_axis ),
866+ ggplot2 :: geom_segment(
867+ ggplot2 :: aes_string(x = " xstart" , y = " ystart" , xend = x_axis , yend = y_axis ),
870868 data = rot_vars ,
871869 lineend = " round" , linejoin = " round" ,
872870 arrow = grid :: arrow(length = grid :: unit(0.5 , " cm" ))
873871 ),
874872 env = list (x_axis = x_axis , y_axis = y_axis )
875873 ),
876874 substitute(
877- geom_label(
878- aes_string(
875+ ggplot2 :: geom_label(
876+ ggplot2 :: aes_string(
879877 x = x_axis ,
880878 y = y_axis ,
881879 label = " label"
@@ -886,7 +884,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
886884 ),
887885 env = list (x_axis = x_axis , y_axis = y_axis )
888886 ),
889- quote(geom_point(aes(x = xstart , y = ystart ), data = rot_vars , shape = " x" , size = 5 ))
887+ quote(ggplot2 :: geom_point(ggplot2 :: aes(x = xstart , y = ystart ), data = rot_vars , shape = " x" , size = 5 ))
890888 )
891889 }
892890
@@ -896,9 +894,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
896894 dev_ggplot2_args <- teal.widgets :: ggplot2_args(
897895 labs = dev_labs ,
898896 theme = list (
899- text = substitute(element_text(size = font_size ), list (font_size = font_size )),
897+ text = substitute(ggplot2 :: element_text(size = font_size ), list (font_size = font_size )),
900898 axis.text.x = substitute(
901- element_text(angle = angle_val , hjust = hjust_val ),
899+ ggplot2 :: element_text(angle = angle_val , hjust = hjust_val ),
902900 list (angle_val = angle , hjust_val = hjust )
903901 )
904902 )
@@ -935,6 +933,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
935933
936934 # plot eigenvector_plot ----
937935 plot_eigenvector <- function (base_q ) {
936+ req(input $ pc )
938937 pc <- input $ pc
939938 ggtheme <- input $ ggtheme
940939
@@ -946,9 +945,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
946945
947946 dev_ggplot2_args <- teal.widgets :: ggplot2_args(
948947 theme = list (
949- text = substitute(element_text(size = font_size ), list (font_size = font_size )),
948+ text = substitute(ggplot2 :: element_text(size = font_size ), list (font_size = font_size )),
950949 axis.text.x = substitute(
951- element_text(angle = angle_val , hjust = hjust_val ),
950+ ggplot2 :: element_text(angle = angle_val , hjust = hjust_val ),
952951 list (angle_val = angle , hjust_val = hjust )
953952 )
954953 )
@@ -969,17 +968,17 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
969968 list (
970969 quote(ggplot(pca_rot )),
971970 substitute(
972- geom_bar(
973- aes_string(x = " Variable" , y = pc ),
971+ ggplot2 :: geom_bar(
972+ ggplot2 :: aes_string(x = " Variable" , y = pc ),
974973 stat = " identity" ,
975974 color = " black" ,
976975 fill = c(getOption(" ggplot2.discrete.colour" ), " lightblue" )[1 ]
977976 ),
978977 env = list (pc = pc )
979978 ),
980979 substitute(
981- geom_text(
982- aes(
980+ ggplot2 :: geom_text(
981+ ggplot2 :: aes(
983982 x = Variable ,
984983 y = pc_name ,
985984 label = round(pc_name , 3 ),
0 commit comments