Skip to content

Commit

Permalink
Add option whether to scale data to unit variance
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJonasJost committed Oct 23, 2024
1 parent 109750a commit 59e232e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions program/shinyApp/R/pca/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ pca_Server <- function(id, data, params, row_select){
check <- check_calculations(list(
sample_selection_pca = input$sample_selection_pca,
SampleAnnotationTypes_pca = input$SampleAnnotationTypes_pca,
batch = ifelse(par_tmp[[session$token]]$BatchColumn != "NULL" && input$UseBatch == "Yes",T,F)
batch = ifelse(par_tmp[[session$token]]$BatchColumn != "NULL" && input$UseBatch == "Yes",T,F),
scale_data = input$scale_data
), "PCA")
if (check == "No Result yet"){
output$PCA_Info <- renderText("PCA computed.")
Expand Down Expand Up @@ -200,7 +201,7 @@ pca_Server <- function(id, data, params, row_select){
pca <- prcomp(
x = as.data.frame(t(as.data.frame(assay(data2plot)))),
center = T,
scale. = FALSE
scale. = ifelse(input$scale_data == "Yes",T,F)
)
}, error = function(e){
error_modal(e)
Expand All @@ -223,7 +224,9 @@ pca_Server <- function(id, data, params, row_select){
# assign par_temp as empty list
par_tmp[[session$token]][["PCA"]] <<- list(
sample_selection_pca = input$sample_selection_pca,
SampleAnnotationTypes_pca = input$SampleAnnotationTypes_pca
SampleAnnotationTypes_pca = input$SampleAnnotationTypes_pca,
batch = ifelse(par_tmp[[session$token]]$BatchColumn != "NULL" && input$UseBatch == "Yes",T,F),
scale_data = input$scale_data
)
} else {
# otherwise read the reactive values
Expand Down
8 changes: 8 additions & 0 deletions program/shinyApp/R/pca/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ pca_sidebar_panel <- function(ns){
),
uiOutput(outputId = ns("SampleAnnotationTypes_pca_ui")),
uiOutput(outputId = ns("sample_selection_pca_ui")),
# Scale data to unit variance y/n
radioGroupButtons(
inputId = ns("scale_data"),
label = "Scale data to unit variance?",
choices = c("Yes","No"),
direction = "horizontal",
selected = "No"
),
### start pca ---
actionButton(
inputId = ns("Do_PCA"),
Expand Down

0 comments on commit 59e232e

Please sign in to comment.