Skip to content
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

712 - {shinytest2} for tm_a_pca #716

Merged
merged 31 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d2d4e1a
feat: support for e2e tests in PCA module
averissimo Apr 10, 2024
a20da5a
fix: remove app view expressions
averissimo Apr 10, 2024
a1a0c94
e2e feat: add remaining data extract input
averissimo Apr 10, 2024
5fb8885
fix: linter errors
averissimo Apr 11, 2024
08292fd
fix: adds ggplot2 prefix to all calls
averissimo Apr 11, 2024
7ebe92a
fix: adds prefix to missing vars() call
averissimo Apr 11, 2024
3cbee3f
fix: remove requirement for loading shinytest2 and adds wait
averissimo Apr 11, 2024
ebb00eb
Apply suggestions from code review
averissimo Apr 11, 2024
e5c3783
feat: move app driver initialization to helper
averissimo Apr 11, 2024
f578c62
feat: split complex test into smaller tests
averissimo Apr 11, 2024
119db66
chore: rename helper name
averissimo Apr 12, 2024
59594fd
chore: remove wait_for_idle as it was implementd upstream
averissimo Apr 12, 2024
e7d14b5
fix: rename missing instances
averissimo Apr 12, 2024
c5fe9e5
fix: missing _driver on call
averissimo Apr 12, 2024
1791583
fix: move helper to test file
averissimo Apr 15, 2024
c7af8ca
adds some expect_no_validation_error
averissimo Apr 15, 2024
4356c72
docs: revert prefixes
averissimo Apr 17, 2024
2abbd29
chore: revert multiline to single line
averissimo Apr 17, 2024
65eab4e
chore: revert change in comment
averissimo Apr 17, 2024
a51e745
Apply suggestions from @m7pr on `set_active_module_input` rename
averissimo Apr 17, 2024
30a6330
Merge branch 'main' into 712-tm_a_pca@main
averissimo Apr 17, 2024
ce2a06e
fix: replace TealAppDriver with init_teal_app_driver
averissimo Apr 17, 2024
98751d4
Update tests/testthat/test-shinytest2-tm_a_pca.R
averissimo Apr 18, 2024
01b4b3b
chore: split tests into multiple
averissimo Apr 18, 2024
f25df6e
docs: adds a simple comment
averissimo Apr 18, 2024
1428f58
fix: wrong expectation
averissimo Apr 18, 2024
b3b2c18
Merge branch 'main' into 712-tm_a_pca@main
averissimo Apr 18, 2024
8f863fe
Merge branch 'main' into 712-tm_a_pca@main
m7pr Apr 19, 2024
e8a5acc
Merge branch 'main' into 712-tm_a_pca@main
averissimo Apr 19, 2024
7099007
Merge branch 'main' into 712-tm_a_pca@main
averissimo Apr 19, 2024
aa9d18c
Merge branch 'main' into 712-tm_a_pca@main
averissimo Apr 22, 2024
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
91 changes: 47 additions & 44 deletions R/tm_a_pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ ui_a_pca <- function(id, ...) {
collapsed = TRUE,
conditionalPanel(
condition = sprintf(
"input['%s'] == 'Elbow Plot' || input['%s'] == 'Eigenvector plot'",
"input['%s'] == 'Elbow plot' || input['%s'] == 'Eigenvector plot'",
ns("plot_type"),
ns("plot_type")
),
Expand Down Expand Up @@ -520,12 +520,12 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
theme = list(
legend.position = "right",
legend.spacing.y = quote(grid::unit(-5, "pt")),
legend.title = quote(element_text(vjust = 25)),
legend.title = quote(ggplot2::element_text(vjust = 25)),
axis.text.x = substitute(
element_text(angle = angle_value, hjust = hjust_value),
ggplot2::element_text(angle = angle_value, hjust = hjust_value),
list(angle_value = angle_value, hjust_value = hjust_value)
),
text = substitute(element_text(size = font_size), list(font_size = font_size))
text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size))
)
)

Expand All @@ -550,24 +550,24 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
)

cols <- c(getOption("ggplot2.discrete.colour"), c("lightblue", "darkred", "black"))[1:3]
g <- ggplot(mapping = aes_string(x = "component", y = "value")) +
geom_bar(
aes(fill = "Single variance"),
g <- ggplot2::ggplot(mapping = ggplot2::aes_string(x = "component", y = "value")) +
ggplot2::geom_bar(
ggplot2::aes(fill = "Single variance"),
data = dplyr::filter(elb_dat, metric == "Proportion of Variance"),
color = "black",
stat = "identity"
) +
geom_point(
aes(color = "Cumulative variance"),
ggplot2::geom_point(
ggplot2::aes(color = "Cumulative variance"),
data = dplyr::filter(elb_dat, metric == "Cumulative Proportion")
) +
geom_line(
aes(group = 1, color = "Cumulative variance"),
ggplot2::geom_line(
ggplot2::aes(group = 1, color = "Cumulative variance"),
data = dplyr::filter(elb_dat, metric == "Cumulative Proportion")
) +
labs +
scale_color_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[3])) +
scale_fill_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[1])) +
ggplot2::scale_color_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[3])) +
ggplot2::scale_fill_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[1])) +
ggthemes +
themes

Expand Down Expand Up @@ -597,9 +597,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl

dev_ggplot2_args <- teal.widgets::ggplot2_args(
theme = list(
text = substitute(element_text(size = font_size), list(font_size = font_size)),
text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)),
axis.text.x = substitute(
element_text(angle = angle_val, hjust = hjust_val),
ggplot2::element_text(angle = angle_val, hjust = hjust_val),
list(angle_val = angle, hjust_val = hjust)
)
)
Expand Down Expand Up @@ -629,15 +629,15 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
y = sin(seq(0, 2 * pi, length.out = 100))
)

g <- ggplot(pca_rot) +
geom_point(aes_string(x = x_axis, y = y_axis)) +
geom_label(
aes_string(x = x_axis, y = y_axis, label = "label"),
g <- ggplot2::ggplot(pca_rot) +
ggplot2::geom_point(ggplot2::aes_string(x = x_axis, y = y_axis)) +
ggplot2::geom_label(
ggplot2::aes_string(x = x_axis, y = y_axis, label = "label"),
nudge_x = 0.1, nudge_y = 0.05,
fontface = "bold"
) +
geom_path(aes(x, y, group = 1), data = circle_data) +
geom_point(aes(x = x, y = y), data = data.frame(x = 0, y = 0), shape = "x", size = 5) +
ggplot2::geom_path(ggplot2::aes(x, y, group = 1), data = circle_data) +
ggplot2::geom_point(ggplot2::aes(x = x, y = y), data = data.frame(x = 0, y = 0), shape = "x", size = 5) +
labs +
ggthemes +
themes
Expand All @@ -648,7 +648,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
y_axis = y_axis,
variables = variables,
ggthemes = parsed_ggplot2_args$ggtheme,
labs = `if`(is.null(parsed_ggplot2_args$labs), quote(labs()), parsed_ggplot2_args$labs),
labs = `if`(is.null(parsed_ggplot2_args$labs), quote(ggplot2::labs()), parsed_ggplot2_args$labs),
themes = parsed_ggplot2_args$theme
)
)
Expand Down Expand Up @@ -694,7 +694,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl

rot_vars <- pca$rotation[, c(x_axis, y_axis)] %>%
dplyr::as_tibble(rownames = "label") %>%
dplyr::mutate_at(vars(c(x_axis, y_axis)), function(x) r * x / sqrt(max(v_scale)))
dplyr::mutate_at(ggplot2::vars(c(x_axis, y_axis)), function(x) r * x / sqrt(max(v_scale)))
},
env = list(x_axis = x_axis, y_axis = y_axis)
)
Expand Down Expand Up @@ -726,13 +726,16 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
)
}

pca_plot_biplot_expr <- list(quote(ggplot()))
pca_plot_biplot_expr <- list(quote(ggplot2::ggplot()))

if (length(resp_col) == 0) {
pca_plot_biplot_expr <- c(
pca_plot_biplot_expr,
substitute(
geom_point(aes_string(x = x_axis, y = y_axis), data = pca_rot, alpha = alpha, size = size),
ggplot2::geom_point(
ggplot2::aes_string(x = x_axis, y = y_axis),
data = pca_rot, alpha = alpha, size = size
),
list(x_axis = input$x_axis, y_axis = input$y_axis, alpha = input$alpha, size = input$size)
)
)
Expand All @@ -743,7 +746,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
response <- ANL[[resp_col]]

aes_biplot <- substitute(
aes_string(x = x_axis, y = y_axis, color = "response"),
ggplot2::aes_string(x = x_axis, y = y_axis, color = "response"),
env = list(x_axis = x_axis, y_axis = y_axis)
)

Expand All @@ -764,15 +767,15 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
qenv,
quote(pca_rot$response <- as.factor(response))
)
quote(scale_color_brewer(palette = "Dark2"))
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(
scale_color_gradient(
ggplot2::scale_color_gradient(
low = c(getOption("ggplot2.discrete.colour")[2], "darkred")[1],
high = c(getOption("ggplot2.discrete.colour"), "lightblue")[1],
labels = function(x) as.Date(x, origin = "1970-01-01")
Expand All @@ -783,7 +786,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
qenv,
quote(pca_rot$response <- response)
)
quote(scale_color_gradient(
quote(ggplot2::scale_color_gradient(
low = c(getOption("ggplot2.discrete.colour")[2], "darkred")[1],
high = c(getOption("ggplot2.discrete.colour"), "lightblue")[1]
))
Expand All @@ -792,7 +795,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
pca_plot_biplot_expr <- c(
pca_plot_biplot_expr,
substitute(
geom_point(aes_biplot, data = pca_rot, alpha = alpha, size = size),
ggplot2::geom_point(aes_biplot, data = pca_rot, alpha = alpha, size = size),
env = list(aes_biplot = aes_biplot, alpha = alpha, size = size)
),
scales_biplot
Expand All @@ -803,17 +806,17 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
pca_plot_biplot_expr <- c(
pca_plot_biplot_expr,
substitute(
geom_segment(
aes_string(x = "xstart", y = "ystart", xend = x_axis, yend = y_axis),
ggplot2::geom_segment(
ggplot2::aes_string(x = "xstart", y = "ystart", xend = x_axis, yend = y_axis),
data = rot_vars,
lineend = "round", linejoin = "round",
arrow = grid::arrow(length = grid::unit(0.5, "cm"))
),
env = list(x_axis = x_axis, y_axis = y_axis)
),
substitute(
geom_label(
aes_string(
ggplot2::geom_label(
ggplot2::aes_string(
x = x_axis,
y = y_axis,
label = "label"
Expand All @@ -824,7 +827,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
),
env = list(x_axis = x_axis, y_axis = y_axis)
),
quote(geom_point(aes(x = xstart, y = ystart), data = rot_vars, shape = "x", size = 5))
quote(ggplot2::geom_point(ggplot2::aes(x = xstart, y = ystart), data = rot_vars, shape = "x", size = 5))
)
}

Expand All @@ -834,9 +837,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
dev_ggplot2_args <- teal.widgets::ggplot2_args(
labs = dev_labs,
theme = list(
text = substitute(element_text(size = font_size), list(font_size = font_size)),
text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)),
axis.text.x = substitute(
element_text(angle = angle_val, hjust = hjust_val),
ggplot2::element_text(angle = angle_val, hjust = hjust_val),
list(angle_val = angle, hjust_val = hjust)
)
)
Expand Down Expand Up @@ -885,9 +888,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl

dev_ggplot2_args <- teal.widgets::ggplot2_args(
theme = list(
text = substitute(element_text(size = font_size), list(font_size = font_size)),
text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)),
axis.text.x = substitute(
element_text(angle = angle_val, hjust = hjust_val),
ggplot2::element_text(angle = angle_val, hjust = hjust_val),
list(angle_val = angle, hjust_val = hjust)
)
)
Expand All @@ -906,19 +909,19 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl

ggplot_exprs <- c(
list(
quote(ggplot(pca_rot)),
quote(ggplot2::ggplot(pca_rot)),
substitute(
geom_bar(
aes_string(x = "Variable", y = pc),
ggplot2::geom_bar(
ggplot2::aes_string(x = "Variable", y = pc),
stat = "identity",
color = "black",
fill = c(getOption("ggplot2.discrete.colour"), "lightblue")[1]
),
env = list(pc = pc)
),
substitute(
geom_text(
aes(
ggplot2::geom_text(
ggplot2::aes(
x = Variable,
y = pc_name,
label = round(pc_name, 3),
Expand Down
Loading
Loading