Skip to content

Commit bf6f6cb

Browse files
committed
Add library calls and prefix.
1 parent a053e94 commit bf6f6cb

13 files changed

+203
-187
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Removed `Show Warnings` modals from modules.
44
* Soft deprecated `datasets_selected` argument of modules in favor of `datanames`.
55
* Soft deprecated `show_metadata` argument of `tm_front_page()` in favor of `datanames`.
6+
* Module's code include library calls and is styled before presenting it to the users.
67

78
### Enhancements
89

R/tm_a_pca.R

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,10 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
438438
selector_list = selector_list,
439439
datasets = data
440440
)
441-
441+
qenv <- teal.code::eval_code(data(), "library('ggplot2')")
442442
anl_merged_q <- reactive({
443443
req(anl_merged_input())
444-
data() %>%
444+
qenv %>%
445445
teal.code::eval_code(as.expression(anl_merged_input()$expr))
446446
})
447447

@@ -585,12 +585,12 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
585585
theme = list(
586586
legend.position = "right",
587587
legend.spacing.y = quote(grid::unit(-5, "pt")),
588-
legend.title = quote(element_text(vjust = 25)),
588+
legend.title = quote(ggplot2::element_text(vjust = 25)),
589589
axis.text.x = substitute(
590-
element_text(angle = angle_value, hjust = hjust_value),
590+
ggplot2::element_text(angle = angle_value, hjust = hjust_value),
591591
list(angle_value = angle_value, hjust_value = hjust_value)
592592
),
593-
text = substitute(element_text(size = font_size), list(font_size = font_size))
593+
text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size))
594594
)
595595
)
596596

@@ -615,24 +615,24 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
615615
)
616616

617617
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"),
618+
elbow_plot <- ggplot2::ggplot(mapping = aes_string(x = "component", y = "value")) +
619+
ggplot2::geom_bar(
620+
ggplot2::aes(fill = "Single variance"),
621621
data = dplyr::filter(elb_dat, metric == "Proportion of Variance"),
622622
color = "black",
623623
stat = "identity"
624624
) +
625-
geom_point(
626-
aes(color = "Cumulative variance"),
625+
ggplot2::geom_point(
626+
ggplot2::aes(color = "Cumulative variance"),
627627
data = dplyr::filter(elb_dat, metric == "Cumulative Proportion")
628628
) +
629-
geom_line(
630-
aes(group = 1, color = "Cumulative variance"),
629+
ggplot2::geom_line(
630+
ggplot2::aes(group = 1, color = "Cumulative variance"),
631631
data = dplyr::filter(elb_dat, metric == "Cumulative Proportion")
632632
) +
633633
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])) +
634+
ggplot2::scale_color_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[3])) +
635+
ggplot2::scale_fill_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[1])) +
636636
ggthemes +
637637
themes
638638
},
@@ -660,9 +660,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
660660

661661
dev_ggplot2_args <- teal.widgets::ggplot2_args(
662662
theme = list(
663-
text = substitute(element_text(size = font_size), list(font_size = font_size)),
663+
text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)),
664664
axis.text.x = substitute(
665-
element_text(angle = angle_val, hjust = hjust_val),
665+
ggplot2::element_text(angle = angle_val, hjust = hjust_val),
666666
list(angle_val = angle, hjust_val = hjust)
667667
)
668668
)
@@ -692,15 +692,15 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
692692
y = sin(seq(0, 2 * pi, length.out = 100))
693693
)
694694

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"),
695+
circle_plot <- ggplot2::ggplot(pca_rot) +
696+
ggplot2::geom_point(ggplot2::aes_string(x = x_axis, y = y_axis)) +
697+
ggplot2::geom_label(
698+
ggplot2::aes_string(x = x_axis, y = y_axis, label = "label"),
699699
nudge_x = 0.1, nudge_y = 0.05,
700700
fontface = "bold"
701701
) +
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) +
702+
ggplot2::geom_path(ggplot2::aes(x, y, group = 1), data = circle_data) +
703+
ggplot2::geom_point(ggplot2::aes(x = x, y = y), data = data.frame(x = 0, y = 0), shape = "x", size = 5) +
704704
labs +
705705
ggthemes +
706706
themes
@@ -794,7 +794,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
794794
pca_plot_biplot_expr <- c(
795795
pca_plot_biplot_expr,
796796
substitute(
797-
geom_point(aes_string(x = x_axis, y = y_axis), data = pca_rot, alpha = alpha, size = size),
797+
ggplot2::geom_point(ggplot2::aes_string(x = x_axis, y = y_axis), data = pca_rot, alpha = alpha, size = size),
798798
list(x_axis = input$x_axis, y_axis = input$y_axis, alpha = input$alpha, size = input$size)
799799
)
800800
)
@@ -805,7 +805,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
805805
response <- ANL[[resp_col]]
806806

807807
aes_biplot <- substitute(
808-
aes_string(x = x_axis, y = y_axis, color = "response"),
808+
ggplot2::aes_string(x = x_axis, y = y_axis, color = "response"),
809809
env = list(x_axis = x_axis, y_axis = y_axis)
810810
)
811811

@@ -826,15 +826,15 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
826826
qenv,
827827
quote(pca_rot$response <- as.factor(response))
828828
)
829-
quote(scale_color_brewer(palette = "Dark2"))
829+
quote(ggplot2::scale_color_brewer(palette = "Dark2"))
830830
} else if (inherits(response, "Date")) {
831831
qenv <- teal.code::eval_code(
832832
qenv,
833833
quote(pca_rot$response <- numeric(response))
834834
)
835835

836836
quote(
837-
scale_color_gradient(
837+
ggplot2::scale_color_gradient(
838838
low = c(getOption("ggplot2.discrete.colour")[2], "darkred")[1],
839839
high = c(getOption("ggplot2.discrete.colour"), "lightblue")[1],
840840
labels = function(x) as.Date(x, origin = "1970-01-01")
@@ -845,7 +845,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
845845
qenv,
846846
quote(pca_rot$response <- response)
847847
)
848-
quote(scale_color_gradient(
848+
quote(ggplot2::scale_color_gradient(
849849
low = c(getOption("ggplot2.discrete.colour")[2], "darkred")[1],
850850
high = c(getOption("ggplot2.discrete.colour"), "lightblue")[1]
851851
))
@@ -854,7 +854,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
854854
pca_plot_biplot_expr <- c(
855855
pca_plot_biplot_expr,
856856
substitute(
857-
geom_point(aes_biplot, data = pca_rot, alpha = alpha, size = size),
857+
ggplot2::geom_point(aes_biplot, data = pca_rot, alpha = alpha, size = size),
858858
env = list(aes_biplot = aes_biplot, alpha = alpha, size = size)
859859
),
860860
scales_biplot
@@ -865,17 +865,17 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
865865
pca_plot_biplot_expr <- c(
866866
pca_plot_biplot_expr,
867867
substitute(
868-
geom_segment(
869-
aes_string(x = "xstart", y = "ystart", xend = x_axis, yend = y_axis),
868+
ggplot2::geom_segment(
869+
ggplot2::aes_string(x = "xstart", y = "ystart", xend = x_axis, yend = y_axis),
870870
data = rot_vars,
871871
lineend = "round", linejoin = "round",
872872
arrow = grid::arrow(length = grid::unit(0.5, "cm"))
873873
),
874874
env = list(x_axis = x_axis, y_axis = y_axis)
875875
),
876876
substitute(
877-
geom_label(
878-
aes_string(
877+
ggplot2::geom_label(
878+
ggplot2::aes_string(
879879
x = x_axis,
880880
y = y_axis,
881881
label = "label"
@@ -886,7 +886,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
886886
),
887887
env = list(x_axis = x_axis, y_axis = y_axis)
888888
),
889-
quote(geom_point(aes(x = xstart, y = ystart), data = rot_vars, shape = "x", size = 5))
889+
quote(ggplot2::geom_point(ggplot2::aes(x = xstart, y = ystart), data = rot_vars, shape = "x", size = 5))
890890
)
891891
}
892892

@@ -896,9 +896,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
896896
dev_ggplot2_args <- teal.widgets::ggplot2_args(
897897
labs = dev_labs,
898898
theme = list(
899-
text = substitute(element_text(size = font_size), list(font_size = font_size)),
899+
text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)),
900900
axis.text.x = substitute(
901-
element_text(angle = angle_val, hjust = hjust_val),
901+
ggplot2::element_text(angle = angle_val, hjust = hjust_val),
902902
list(angle_val = angle, hjust_val = hjust)
903903
)
904904
)
@@ -946,9 +946,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
946946

947947
dev_ggplot2_args <- teal.widgets::ggplot2_args(
948948
theme = list(
949-
text = substitute(element_text(size = font_size), list(font_size = font_size)),
949+
text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)),
950950
axis.text.x = substitute(
951-
element_text(angle = angle_val, hjust = hjust_val),
951+
ggplot2::element_text(angle = angle_val, hjust = hjust_val),
952952
list(angle_val = angle, hjust_val = hjust)
953953
)
954954
)
@@ -969,17 +969,17 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
969969
list(
970970
quote(ggplot(pca_rot)),
971971
substitute(
972-
geom_bar(
973-
aes_string(x = "Variable", y = pc),
972+
ggplot2::geom_bar(
973+
ggplot2::aes_string(x = "Variable", y = pc),
974974
stat = "identity",
975975
color = "black",
976976
fill = c(getOption("ggplot2.discrete.colour"), "lightblue")[1]
977977
),
978978
env = list(pc = pc)
979979
),
980980
substitute(
981-
geom_text(
982-
aes(
981+
ggplot2::geom_text(
982+
ggplot2::aes(
983983
x = Variable,
984984
y = pc_name,
985985
label = round(pc_name, 3),

R/tm_a_regression.R

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,12 @@ srv_a_regression <- function(id,
448448
)
449449
})
450450

451+
qenv <- teal.code::eval_code(data(),
452+
"library('ggplot2');")
453+
451454
anl_merged_q <- reactive({
452455
req(anl_merged_input())
453-
data() %>%
456+
qenv %>%
454457
teal.code::eval_code(as.expression(anl_merged_input()$expr))
455458
})
456459

@@ -585,8 +588,8 @@ srv_a_regression <- function(id,
585588
shinyjs::show("size")
586589
shinyjs::show("alpha")
587590
plot <- substitute(
588-
expr = ggplot(fit$model[, 2:1], aes_string(regressor, response)) +
589-
geom_point(size = size, alpha = alpha) +
591+
expr = ggplot2::ggplot(fit$model[, 2:1], ggplot2::aes_string(regressor, response)) +
592+
ggplot2::geom_point(size = size, alpha = alpha) +
590593
stat_smooth(method = "lm", formula = y ~ x, se = FALSE),
591594
env = list(
592595
regressor = regression_var()$regressor,
@@ -605,8 +608,8 @@ srv_a_regression <- function(id,
605608
shinyjs::hide("size")
606609
shinyjs::hide("alpha")
607610
plot <- substitute(
608-
expr = ggplot(fit$model[, 2:1], aes_string(regressor, response)) +
609-
geom_boxplot(),
611+
expr = ggplot2::ggplot(fit$model[, 2:1], ggplot2::aes_string(regressor, response)) +
612+
ggplot2::geom_boxplot(),
610613
env = list(regressor = regression_var()$regressor, response = regression_var()$response)
611614
)
612615
if (input$show_outlier) {
@@ -650,10 +653,10 @@ srv_a_regression <- function(id,
650653
shinyjs::show("size")
651654
shinyjs::show("alpha")
652655
plot <- substitute(
653-
expr = ggplot(data = data, aes(.fitted, .resid)) +
654-
geom_point(size = size, alpha = alpha) +
655-
geom_hline(yintercept = 0, linetype = "dashed", size = 1) +
656-
geom_line(data = smoothy, mapping = smoothy_aes),
656+
expr = ggplot2::ggplot(data = data, ggplot2::aes(.fitted, .resid)) +
657+
ggplot2::geom_point(size = size, alpha = alpha) +
658+
ggplot2::geom_hline(yintercept = 0, linetype = "dashed", size = 1) +
659+
ggplot2::geom_line(data = smoothy, mapping = smoothy_aes),
657660
env = list(size = input$size, alpha = input$alpha)
658661
)
659662
if (input$show_outlier) {
@@ -694,15 +697,15 @@ srv_a_regression <- function(id,
694697
shinyjs::show("alpha")
695698
plot_base <- output_plot_base()
696699
plot <- substitute(
697-
expr = ggplot(data = data, aes(sample = .stdresid)) +
698-
stat_qq(size = size, alpha = alpha) +
699-
geom_abline(linetype = "dashed"),
700+
expr = ggplot2::ggplot(data = data, ggplot2::aes(sample = .stdresid)) +
701+
ggplot2::stat_qq(size = size, alpha = alpha) +
702+
ggplot2::geom_abline(linetype = "dashed"),
700703
env = list(size = input$size, alpha = input$alpha)
701704
)
702705
if (input$show_outlier) {
703706
plot <- substitute(
704707
expr = plot +
705-
stat_qq(
708+
ggplot2::stat_qq(
706709
geom = ggrepel::GeomTextRepel,
707710
label = label_col %>%
708711
data.frame(label = .) %>%
@@ -753,9 +756,9 @@ srv_a_regression <- function(id,
753756
shinyjs::show("alpha")
754757
plot_base <- output_plot_base()
755758
plot <- substitute(
756-
expr = ggplot(data = data, aes(.fitted, sqrt(abs(.stdresid)))) +
757-
geom_point(size = size, alpha = alpha) +
758-
geom_line(data = smoothy, mapping = smoothy_aes),
759+
expr = ggplot2::ggplot(data = data, ggplot2::aes(.fitted, sqrt(abs(.stdresid)))) +
760+
ggplot2::geom_point(size = size, alpha = alpha) +
761+
ggplot2::geom_line(data = smoothy, mapping = smoothy_aes),
759762
env = list(size = input$size, alpha = input$alpha)
760763
)
761764
if (input$show_outlier) {
@@ -796,23 +799,23 @@ srv_a_regression <- function(id,
796799
shinyjs::show("alpha")
797800
plot_base <- output_plot_base()
798801
plot <- substitute(
799-
expr = ggplot(data = data, aes(seq_along(.cooksd), .cooksd)) +
800-
geom_col(alpha = alpha),
802+
expr = ggplot2::ggplot(data = data, ggplot2::aes(seq_along(.cooksd), .cooksd)) +
803+
ggplot2::geom_col(alpha = alpha),
801804
env = list(alpha = input$alpha)
802805
)
803806
if (input$show_outlier) {
804807
plot <- substitute(
805808
expr = plot +
806-
geom_hline(
809+
ggplot2::geom_hline(
807810
yintercept = c(
808811
outlier * mean(data$.cooksd, na.rm = TRUE),
809812
mean(data$.cooksd, na.rm = TRUE)
810813
),
811814
color = "red",
812815
linetype = "dashed"
813816
) +
814-
geom_text(
815-
aes(
817+
ggplot2::geom_text(
818+
ggplot2::aes(
816819
x = 0,
817820
y = mean(data$.cooksd, na.rm = TRUE),
818821
label = paste("mu", "=", round(mean(data$.cooksd, na.rm = TRUE), 4)),
@@ -862,21 +865,21 @@ srv_a_regression <- function(id,
862865
shinyjs::show("alpha")
863866
plot_base <- output_plot_base()
864867
plot <- substitute(
865-
expr = ggplot(data = data, aes(.hat, .stdresid)) +
866-
geom_vline(
868+
expr = ggplot2::ggplot(data = data, ggplot2::aes(.hat, .stdresid)) +
869+
ggplot2::geom_vline(
867870
size = 1,
868871
colour = "black",
869872
linetype = "dashed",
870873
xintercept = 0
871874
) +
872-
geom_hline(
875+
ggplot2::geom_hline(
873876
size = 1,
874877
colour = "black",
875878
linetype = "dashed",
876879
yintercept = 0
877880
) +
878-
geom_point(size = size, alpha = alpha) +
879-
geom_line(data = smoothy, mapping = smoothy_aes),
881+
ggplot2::geom_point(size = size, alpha = alpha) +
882+
ggplot2::geom_line(data = smoothy, mapping = smoothy_aes),
880883
env = list(size = input$size, alpha = input$alpha)
881884
)
882885
if (input$show_outlier) {
@@ -917,16 +920,16 @@ srv_a_regression <- function(id,
917920
shinyjs::show("alpha")
918921
plot_base <- output_plot_base()
919922
plot <- substitute(
920-
expr = ggplot(data = data, aes(.hat, .cooksd)) +
921-
geom_vline(xintercept = 0, colour = NA) +
922-
geom_abline(
923+
expr = ggplot2::ggplot(data = data, ggplot2::aes(.hat, .cooksd)) +
924+
ggplot2::geom_vline(xintercept = 0, colour = NA) +
925+
ggplot2::geom_abline(
923926
slope = seq(0, 3, by = 0.5),
924927
colour = "black",
925928
linetype = "dashed",
926929
size = 1
927930
) +
928-
geom_line(data = smoothy, mapping = smoothy_aes) +
929-
geom_point(size = size, alpha = alpha),
931+
ggplot2::geom_line(data = smoothy, mapping = smoothy_aes) +
932+
ggplot2::geom_point(size = size, alpha = alpha),
930933
env = list(size = input$size, alpha = input$alpha)
931934
)
932935
if (input$show_outlier) {

0 commit comments

Comments
 (0)