-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.R
179 lines (156 loc) · 5.66 KB
/
server.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# LIBRARIES -----------------------------------------------------------------
library(shiny)
# library(reactlog)
library(shinyTree)
library(tibble)
library(shinyBS)
library(plotly)
library(shinythemes)
library(ggplot2)
library(DT)
library(pheatmap)
library(threejs)
library(sm)
library(RColorBrewer)
library(mclust)
library(reshape)
library(ggplot2)
library(knitr)
library(kableExtra)
library(shinyWidgets)
library(scater)
library(shinyMCE)
library(kohonen)
library(Rsomoclu)
library(gtools)
library(SingleCellExperiment)
library(Matrix)
library(colourpicker)
library(shinytest)
library(scran)
library(callr)
library(debugme)
if (file.exists("defaultValues.R")) {
base::source(file = "defaultValues.R")
} else {
base::warning("no defaultsValues.R file")
base::stop("stop")
}
# list available colors for samples and clusters, other colors are defined independantly.
if (!exists("allowedColors")) {
allowedColors = unique(c("#8c510a","#d8b365","#f6e8c3","#c7eae5","#5ab4ac","#01665e","#c51b7d","#e9a3c9",
"#fde0ef","#e6f5d0","#a1d76a","#4d9221","#762a83","#af8dc3","#e7d4e8","#d9f0d3",
"#7fbf7b","#1b7837","#b35806","#f1a340","#fee0b6","#d8daeb","#998ec3","#542788",
"#b2182b","#ef8a62","#fddbc7","#d1e5f0","#67a9cf","#2166ac","#b2182b","#ef8a62",
"#fddbc7","#e0e0e0","#999999","#4d4d4d"))
}
Sys.setenv(DEBUGME = ".")
base::source("serverFunctions.R")
# TODO needs to be an option
seed <- 2
# enableBookmarking(store = "server")
# global variable with directory where to store files to be included in reports
reportTempDir <<- base::tempdir()
shinyServer(function(input, output, session) {
base::set.seed(seed)
# check that directory is availabl, otherwise create it
if (DEBUG) {
if (!dir.exists("~/scShinyHubDebug")) {
base::dir.create("~/scShinyHubDebug")
}
# TODO ??? clean directory??
}
# files to be included in report
# developers can add in outputs.R a variable called "myZippedReportFiles"
zippedReportFiles <- c("report.html", "sessionData.RData",
"normalizedCounts.csv", "variables.used.txt",
"inputUsed.RData")
base::options(shiny.maxRequestSize = 2000 * 1024^2)
# TODO check if file exists
# TODO have this as an option to load other files
base::load(file = "geneLists.RData")
if (DEBUG) base::cat(file = stderr(), "ShinyServer running\n")
# base calculations that are quite expensive to calculate
# display name, reactive name to be executed
heavyCalculations <- list(
c("pca", "pca"),
c("scran_Cluster", "scran_Cluster"),
c("projections", "projections")
)
# base projections
# display name, reactive to calculate projections
projectionFunctions <<- list(
c("sampleNames", "sample"),
c("Gene count", "geneCount"),
c("UMI count", "umiCount"),
c("before filter", "beforeFilterPrj")
)
# differential expression functions
# used in subcluster analysis
diffExpFunctions <<- list()
# load global reactives, modules, etc ----
base::source("reactives.R", local = TRUE)
base::source("outputs.R", local = TRUE)
base::source("modulesUI.R", local = TRUE)
base::source("moduleServer.R", local = TRUE)
# bookmarking ----
# couldn't get bookmarking to work, esp. with the input file
# setBookmarkExclude(c("bookmark1"))
# observeEvent(input$bookmark1, {
# if (DEBUG) cat(file = stderr(), paste("bookmarking: \n"))
# if (DEBUG) cat(file = stderr(), paste(names(input), collapse = "\n"))
#
# session$doBookmark()
# if (DEBUG) cat(file = stderr(), paste("bookmarking: DONE\n"))
# })
# Need to exclude the buttons from themselves being bookmarked
# load contribution reactives ----
# parse all reactives.R files under contributions to include in application
uiFiles <- base::dir(
path = "contributions", pattern = "reactives.R",
full.names = TRUE, recursive = TRUE
)
for (fp in uiFiles) {
if (DEBUG) base::cat(file = stderr(), paste("loading: ", fp, "\n"))
myHeavyCalculations <- NULL
myProjections <- NULL
myDiffExpFunctions <- NULL
base::source(fp, local = TRUE)
heavyCalculations <- append2list(myHeavyCalculations, heavyCalculations)
projectionFunctions <- append2list(myProjections, projectionFunctions)
diffExpFunctions <- append2list(myDiffExpFunctions, diffExpFunctions)
}
# update diffExpression radiobutton
dgeChoices = c()
if (length(diffExpFunctions) > 0) {
for (li in 1:length(diffExpFunctions)) {
liVal <- diffExpFunctions[[li]]
if (length(liVal) == 2) {
dgeChoices = c(dgeChoices, liVal[1])
} else {
# shouldn't happen
error("number of values for normalization function is not 2\n")
}
}
}
updateRadioButtons(session = session, inputId = "sCA_dgeRadioButton",
choices = dgeChoices)
# make variable global
diffExpFunctions <<- diffExpFunctions
# load contribution outputs ----
# parse all outputs.R files under contributions to include in application
uiFiles <- base::dir(path = "contributions", pattern = "outputs.R",
full.names = TRUE, recursive = TRUE)
for (fp in uiFiles) {
if (DEBUG) cat(file = stderr(), paste("loading: ", fp, "\n"))
myHeavyCalculations <- NULL
myProjections <- NULL
myZippedReportFiles <- c()
base::source(fp, local = TRUE)
heavyCalculations <- append2list(myHeavyCalculations, heavyCalculations)
projectionFunctions <<- append2list(myProjections, projectionFunctions)
zippedReportFiles <- c(zippedReportFiles, myZippedReportFiles)
}
}) # END SERVER
# shiny::showReactLog()
# enableBookmarking(store = "server")