|
1 | 1 | #' Principal component analysis module |
2 | | -#' @md |
| 2 | +#' |
| 3 | +#' Module conducts principal component analysis (PCA) on a given dataset and offers different |
| 4 | +#' ways of visualizing the outcomes, including elbow plot, circle plot, biplot, and eigenvector plot. |
| 5 | +#' Additionally, it enables dynamic customization of plot aesthetics, such as opacity, size, and |
| 6 | +#' font size, through UI inputs. |
3 | 7 | #' |
4 | 8 | #' @inheritParams teal::module |
5 | 9 | #' @inheritParams shared_params |
6 | 10 | #' @param dat (`data_extract_spec` or `list` of multiple `data_extract_spec`) |
7 | | -#' Columns used to compute PCA. |
8 | | -#' @param alpha optional, (`numeric`) If scalar then the plot points will have a fixed opacity. If a |
9 | | -#' slider should be presented to adjust the plot point opacity dynamically then it can be a vector of |
10 | | -#' length three with `c(value, min, max)`. |
11 | | -#' @param size optional, (`numeric`) If scalar then the plot point sizes will have a fixed size. |
12 | | -#' If a slider should be presented to adjust the plot point sizes dynamically then it can be a |
13 | | -#' vector of length three with `c(value, min, max)`. |
14 | | -#' @param font_size optional, (`numeric`) font size control for title, x-axis label, y-axis label and legend. |
15 | | -#' If scalar then the font size will have a fixed size. If a slider should be presented to adjust the plot |
16 | | -#' point sizes dynamically then it can be a vector of length three with `c(value, min, max)`. |
17 | | -#' |
| 11 | +#' specifying columns used to compute PCA. |
| 12 | +#' @param alpha (`numeric`, optional) Specifies point opacity. |
| 13 | +#' - If vector of `length == 1` then the plot points will have a fixed opacity. |
| 14 | +#' - while vector of `value`, `min`, and `max` allows dynamic adjustment. |
| 15 | +#' @param size (`numeric`, optional) Specifies point size. |
| 16 | +#' - If vector of `length == 1` then the plot point sizes will have a fixed size |
| 17 | +#' - while vector of `value`, `min`, and `max` allows dynamic adjustment. |
| 18 | +#' @param font_size (`numeric`, optional) Specifies font size. |
| 19 | +#' It controls the font size for plot titles, axis labels, and legends. |
| 20 | +#' - If vector of `length == 1` then the font sizes will have a fixed size. |
| 21 | +#' - while vector of `value`, `min`, and `max` allows dynamic adjustment. |
18 | 22 | #' @templateVar ggnames "Elbow plot", "Circle plot", "Biplot", "Eigenvector plot" |
19 | 23 | #' @template ggplot2_args_multi |
20 | 24 | #' |
21 | 25 | #' @examples |
22 | | -#' # general data example |
23 | 26 | #' library(teal.widgets) |
24 | 27 | #' |
| 28 | +#' # general data example |
25 | 29 | #' data <- teal_data() |
26 | 30 | #' data <- within(data, { |
27 | 31 | #' require(nestcolor) |
28 | 32 | #' USArrests <- USArrests |
29 | 33 | #' }) |
| 34 | +#' |
30 | 35 | #' datanames(data) <- "USArrests" |
31 | 36 | #' |
32 | 37 | #' app <- init( |
|
51 | 56 | #' ) |
52 | 57 | #' ) |
53 | 58 | #' ) |
54 | | -#' |
55 | 59 | #' if (interactive()) { |
56 | 60 | #' shinyApp(app$ui, app$server) |
57 | 61 | #' } |
58 | 62 | #' |
59 | 63 | #' # CDISC data example |
60 | | -#' library(teal.widgets) |
61 | | -#' |
62 | 64 | #' data <- teal_data() |
63 | 65 | #' data <- within(data, { |
64 | 66 | #' require(nestcolor) |
|
70 | 72 | #' app <- init( |
71 | 73 | #' data = data, |
72 | 74 | #' modules = modules( |
73 | | -#' teal.modules.general::tm_a_pca( |
| 75 | +#' tm_a_pca( |
74 | 76 | #' "PCA", |
75 | 77 | #' dat = data_extract_spec( |
76 | 78 | #' dataname = "ADSL", |
|
89 | 91 | #' ) |
90 | 92 | #' ) |
91 | 93 | #' ) |
92 | | -#' |
93 | 94 | #' if (interactive()) { |
94 | 95 | #' shinyApp(app$ui, app$server) |
95 | 96 | #' } |
@@ -171,7 +172,7 @@ tm_a_pca <- function(label = "Principal Component Analysis", |
171 | 172 | ) |
172 | 173 | } |
173 | 174 |
|
174 | | - |
| 175 | +# UI function for the PCA module |
175 | 176 | ui_a_pca <- function(id, ...) { |
176 | 177 | ns <- NS(id) |
177 | 178 | args <- list(...) |
@@ -282,6 +283,7 @@ ui_a_pca <- function(id, ...) { |
282 | 283 | ) |
283 | 284 | } |
284 | 285 |
|
| 286 | +# Server function for the PCA module |
285 | 287 | srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, plot_width, ggplot2_args) { |
286 | 288 | with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") |
287 | 289 | with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") |
|
0 commit comments