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

pre-release tm_a_pca document update #646

Merged
merged 11 commits into from
Feb 26, 2024
40 changes: 23 additions & 17 deletions R/tm_a_pca.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
#' Principal component analysis module
#' @md
#'
#' Module conducts principal component analysis (PCA) on a given dataset and offers different
#' ways of visualizing the outcomes, including elbow plot, circle plot, biplot, and eigenvector plot.
#' Additionally, it enables dynamic customization of plot aesthetics, such as opacity, size, and
#' font size, through UI inputs.
#'
#' @inheritParams teal::module
#' @inheritParams shared_params
#' @param dat (`data_extract_spec` or `list` of multiple `data_extract_spec`)
#' Columns used to compute PCA.
#' @param alpha optional, (`numeric`) If scalar then the plot points will have a fixed opacity. If a
#' slider should be presented to adjust the plot point opacity dynamically then it can be a vector of
#' length three with `c(value, min, max)`.
#' @param size optional, (`numeric`) If scalar then the plot point sizes will have a fixed size.
#' If a slider should be presented to adjust the plot point sizes dynamically then it can be a
#' vector of length three with `c(value, min, max)`.
#' @param font_size optional, (`numeric`) font size control for title, x-axis label, y-axis label and legend.
#' If scalar then the font size will have a fixed size. If a slider should be presented to adjust the plot
#' point sizes dynamically then it can be a vector of length three with `c(value, min, max)`.
#'
#' specifying columns used to compute PCA.
#' @param alpha (`numeric`, optional) value or a vector of length three in the form `c(value, min, max)`.
kartikeyakirar marked this conversation as resolved.
Show resolved Hide resolved
#' - If provided as a vector of `length==1`, it sets a fixed opacity for plot points.
#' - If provided as a vector of `length>1`, it allows dynamic adjustment of plot point opacity via a slider in the UI.
#' @param size (`numeric`, optional) value or a vector of length three in the form `c(value, min, max)`.
#' - If provided as a scalar, it sets a fixed size for plot points.
#' - If provided as a vector, it allows dynamic adjustment of plot point sizes via a slider in the UI.
#' @param font_size (`numeric`, optional) value or a vector of length three in the form `c(value, min, max)`.
#' It controls the font size for plot titles, axis labels, and legends.
#' - If vector of `length==1` then the font size will have a fixed size.
#' - If vector of `length>1`, it enables dynamic adjustment of font size via a slider in the UI.
#' @templateVar ggnames "Elbow plot", "Circle plot", "Biplot", "Eigenvector plot"
#' @template ggplot2_args_multi
#'
#' @examples
#' # general data example
#' library(teal.widgets)
m7pr marked this conversation as resolved.
Show resolved Hide resolved
#'
#' # General data example
kartikeyakirar marked this conversation as resolved.
Show resolved Hide resolved
#' data <- teal_data()
#' data <- within(data, {
#' library(nestcolor)
#' USArrests <- USArrests
#' })
#'
#' datanames(data) <- "USArrests"
#'
#' app <- init(
Expand Down Expand Up @@ -57,8 +62,6 @@
#' }
#'
#' # CDISC data example
#' library(teal.widgets)
#'
#' data <- teal_data()
#' data <- within(data, {
#' library(nestcolor)
Expand All @@ -70,7 +73,7 @@
#' app <- init(
#' data = data,
#' modules = modules(
#' teal.modules.general::tm_a_pca(
#' tm_a_pca(
#' "PCA",
#' dat = data_extract_spec(
#' dataname = "ADSL",
Expand Down Expand Up @@ -171,7 +174,8 @@ tm_a_pca <- function(label = "Principal Component Analysis",
)
}


# UI function for the PCA module
# This function defines the UI elements for the PCA analysis, including plot settings and data selection.
m7pr marked this conversation as resolved.
Show resolved Hide resolved
ui_a_pca <- function(id, ...) {
ns <- NS(id)
args <- list(...)
Expand Down Expand Up @@ -282,6 +286,8 @@ ui_a_pca <- function(id, ...) {
)
}

# Server function for the PCA module
# This function handles the server-side logic for PCA analysis, including data processing and plot generation.
m7pr marked this conversation as resolved.
Show resolved Hide resolved
srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, plot_width, ggplot2_args) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
Expand Down
43 changes: 26 additions & 17 deletions man/tm_a_pca.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.