forked from nataliekoh/ShinyQA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
333 lines (308 loc) · 17.4 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
library(shiny); library(DT); library(shinyjs)
library(dplyr); library(digest); library(knitr)
setwd(getwd())
PROJECTDIR <- file.path("/mnt/panuc/udallp2")
fieldsMandatory <- c("subid", "taskid", "sessionid", "userid", "parrecQA",
"rawmoviesQA", "tsnrQA", "meicaQA", "motionQA", "regQA", "Comments")
fieldsAll <- c("subid", "taskid", "sessionid", "userid", "parrecQA",
"rawmoviesQA", "tsnrQA", "meicaQA", "motionQA", "regQA", "Comments")
responsesDir <- "output"
epochTime <- function(){as.integer(Sys.time())}
humanTime <- function(){format(Sys.time(), "%Y%m%d-%H%M")}
saveData <- function(data) {
fileName <- sprintf("%s_%s.csv", humanTime(), digest::digest(data))
write.csv(x = data, file = file.path(responsesDir, fileName),
row.names = FALSE, quote = FALSE)
}
loadData <- function() {
files <- list.files(file.path(responsesDir), full.names = TRUE)
data <- lapply(files, read.csv, stringsAsFactors = FALSE)
data <- dplyr::rbind_all(data)
data
}
function(input, output, session) {
#subid
subject <- reactive({ input$subid })
output$subject <- renderText({ input$subid })
output$subviewtext <- renderText({ paste("You are now viewing subject ",
input$subid, "for", input$taskid,
":", input$sessionid) })
#paths to all QA images
output$rawe001x <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e001_x_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$rawe001y <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e001_y_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$rawe001z <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e001_z_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$rawe002x <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e002_x_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$rawe002y <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e002_y_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$rawe002z <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e002_z_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$rawe003x <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e003_x_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$rawe003y <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e003_y_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$rawe003z <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e003_z_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$tsnr.e001x <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e001_tsnr_mean_x.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$tsnr.e001y <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e001_tsnr_mean_y.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$tsnr.e001z <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e001_tsnr_mean_z.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$tsnr.e002x <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e002_tsnr_mean_x.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$tsnr.e002y <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e002_tsnr_mean_y.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$tsnr.e002z <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e002_tsnr_mean_z.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$tsnr.e003x <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e003_tsnr_mean_x.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$tsnr.e003y <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e003_tsnr_mean_y.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$tsnr.e003z <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e003_tsnr_mean_z.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$meica.tsocx <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e00213_tsoc_x_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$rmeica.tsocy <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"rest-on_e00213_tsoc_y_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$meica.tsocz <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e00213_tsoc_z_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$meica.mednx <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e00213_medn_x_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$meica.medny <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e00213_medn_y_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$meica.mednz <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e00213_medn_z_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$meica.mefcx <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e00213_mefc_x_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$meica.mefcy <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e00213_mefc_y_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$meica.mefcz <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e00213_mefc_z_animation.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$motion.rot <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e002_MotionGraphRotations.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$motion.trans <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e002_MotionGraphTranslations.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$motion.fd <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e002_FramewiseDisplacement.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$motion.dvars02 <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e002_DVARS_raw.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$motion.dvars.tsocmedn <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e002_DVARS_dn-oc.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$tsocT1 <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e00213_tsoc_reoriented_to_T1.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$tsocCT <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e00213_tsoc_to_CT_epireg_ants.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
output$tsocMNI <- renderImage({
filename <- normalizePath(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/images/", input$taskid,
"_e00213_tsoc_reoriented_to_mni_epireg_ants.gif", sep = "")))
list(src = filename)}, deleteFile = FALSE)
#warnings
output$warnings <- renderUI({
HTML(markdown::markdownToHTML(knit(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/", input$taskid, "_warning.Rmd", sep = "")),
quiet = TRUE)))})
#quantitative measures
output$motionmetrics <- renderUI({
HTML(markdown::markdownToHTML(knit(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/", input$taskid, "_motion.Rmd", sep = "")),
quiet = TRUE)))})
#acquisition parameters
output$acqpar <- renderUI({
HTML(markdown::markdownToHTML(knit(file.path(PROJECTDIR, "subjects",
paste(input$subid, "/", input$sessionid,
"/QA/", input$taskid, "_parrec.Rmd", sep = "")),
quiet = TRUE)))})
#form
observe({
mandatoryFilled <- vapply(fieldsMandatory, function(x) {
!is.null(input[[x]]) && input[[x]] != ""},
logical(1))
mandatoryFilled <- all(mandatoryFilled)
shinyjs::toggleState(id = "submit", condition = mandatoryFilled)
})
formData <- reactive({
data <- sapply(fieldsAll, function(x) input[[x]])
data <- c(data, timestamp = humanTime())
data <- t(data)
data
})
observeEvent(input$submit, {
shinyjs::disable("submit")
shinyjs::show("submit_msg")
shinyjs::hide("error")
tryCatch({
saveData(formData())
shinyjs::reset("form")
shinyjs::hide("form")
shinyjs::show("submitted_msg")
}, error = function(err) {
shinyjs::html("error_msg", err$message)
shinyjs::show(id = "error", anim = TRUE)
}, finally = {
shinyjs::enable("submit")
shinyjs::hide("submit_msg")
})
})
observeEvent(input$submit_another, {
shinyjs::show("form")
shinyjs::hide("submitted_msg")
})
#logsheet table display
output$responsesTable <- DT::renderDataTable(
loadData(),
rownames = FALSE,
options = list(searching = FALSE, lengthChange = FALSE)
)
#download data
output$downloadData <- downloadHandler(
function() {
filename = sprintf("rest-on_QALogSheet_%s.csv", humanTime())
},
content = function(file) {
write.csv(loadData(), file, row.names = FALSE)
})
}