Skip to content

Commit

Permalink
- extract dir selection to a function
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-enzlein committed Jun 5, 2024
1 parent 4f61643 commit a739bda
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 41 deletions.
49 changes: 8 additions & 41 deletions components/server.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Sever ####
server <- function(input, output, session) {

## load ext. functions ####
source("functions/loadAllFunctions.R")
loadAllFunctions()
Expand All @@ -10,30 +9,8 @@ server <- function(input, output, session) {

## main ####
appData <<- emptyAppDataObject()
vol <- getVolumes()

# check if "dir" is set in defaults
if (!is.null(defaults$dir)) {
appData$selected_dir <- defaults$dir
message("Dir set from loaded default value.\n")
appData$info_state <- "dir_set"
}

### choose dir ####
shinyDirChoose(input,
"dir",
roots = vol,
allowDirCreate = FALSE,
defaultRoot = names(vol)[1])

observeEvent(input$dir, {
# check if folder was selected
# prepare info massage
appData$selected_dir <- parseDirPath(vol, input$dir)
if (length(appData$selected_dir) > 0) {
appData$info_state <- "dir_set"
}
})

appData <- selectDir(appData, input)

observeEvent(input$preproc_settings, {
appData <- setPreprocessSettings(input, appData)
Expand Down Expand Up @@ -94,7 +71,6 @@ server <- function(input, output, session) {
return()
}


#### average spectra ####
message(MALDIcellassay:::timeNow(), " calculating ", input$avgMethod, " spectra... \n")
avg <- MALDIcellassay:::.aggregateSpectra(spec = prc$spec,
Expand Down Expand Up @@ -155,7 +131,6 @@ server <- function(input, output, session) {
input = input)) {
return()
}

message(MALDIcellassay:::timeNow(), " processing done\n")

# write everything needed into appData
Expand All @@ -176,8 +151,6 @@ server <- function(input, output, session) {
output$mzTable <- createDataTable(appData$stats,
plot_ready = appData$show_plot)



# on reprocess or if data is send from PCA or clustering
observeEvent(appData$stats, {
output$mzTable <- createDataTable(appData$stats,
Expand All @@ -200,7 +173,6 @@ server <- function(input, output, session) {
} else {
dummyPlot()
}

})

output$peak <- renderPlotly({
Expand All @@ -213,7 +185,6 @@ server <- function(input, output, session) {
} else {
dummyPlot()
}

})

### score plot ####
Expand All @@ -225,7 +196,7 @@ server <- function(input, output, session) {
}
})

#### QC tab ####
### QC tab ####
# re-calibration check
output$checkRecal <- renderPlotly({
if (appData$show_plot) {
Expand All @@ -234,9 +205,7 @@ server <- function(input, output, session) {
ggplotly(p)
} else {
dummyPlot()

}

})

# platemap
Expand Down Expand Up @@ -265,7 +234,7 @@ server <- function(input, output, session) {
})
})

#### PCA tab ####
### PCA tab ####
# default plot for PCA
output$pca <- renderPlotly({
dummyPlot()
Expand Down Expand Up @@ -303,10 +272,8 @@ server <- function(input, output, session) {
simple = input$simpleLoadings)

return(p)

} else {
dummyPlot()

}
})

Expand Down Expand Up @@ -335,14 +302,15 @@ server <- function(input, output, session) {
}
})

#### clustering tab #####
### clustering tab #####
observeEvent(input$doClust, {
if (appData$show_plot) {
show_spinner()
appData$clust <- clusterCurves(appData$res, nClusters = 15)
hide_spinner()
}
})

output$clustPlot <- renderPlotly({
if (appData$show_plot & !is.null(appData$clust)) {
show_spinner()
Expand All @@ -369,7 +337,6 @@ server <- function(input, output, session) {
}
})


observeEvent(input$clust2peaksTable, {
if (appData$show_plot & !is.null(appData$clust)) {

Expand All @@ -380,13 +347,13 @@ server <- function(input, output, session) {
}
})

#### save settings ####
### save settings ####
observeEvent(input$saveSettings, {
saveSettings(input, filename = "settings.csv", info_state = appData$info_state)

})

#### download handler ####
### download handler ####
output$downloadPlot <- downloadHandlerPlots(res = appData$res,
selected_row = input$mzTable_rows_selected[1],
p_curve = p_curve,
Expand Down
1 change: 1 addition & 0 deletions functions/loadAllFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ loadAllFunctions <- function() {
source("functions/detectOutliers.R")
source("functions/handlePreprocSettings.R")
source("functions/loadSpectraData.R")
source("functions/selectDir.R")
}


28 changes: 28 additions & 0 deletions functions/selectDir.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
selectDir <- function(appData, input) {
vol <- getVolumes()

# check if "dir" is set in defaults
if (!is.null(defaults$dir)) {
appData$selected_dir <- defaults$dir
message("Dir set from loaded default value.\n")
appData$info_state <- "dir_set"
}

### choose dir ####
shinyDirChoose(input,
"dir",
roots = vol,
allowDirCreate = FALSE,
defaultRoot = names(vol)[1])

observeEvent(input$dir, {
# check if folder was selected
# prepare info massage
appData$selected_dir <- parseDirPath(vol, input$dir)
if (length(appData$selected_dir) > 0) {
appData$info_state <- "dir_set"
}
})

return(appData)
}

0 comments on commit a739bda

Please sign in to comment.