-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
574 lines (466 loc) · 25.3 KB
/
app.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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
# load data & packages ----------------------------------------------------
library(shiny)
library(vitessce)
library(Seurat)
source("tailored-demo-helpers.R")
#####basic demo
#load datasets
data_pbmc_results <- readRDS("data/data_pbmc_results.rds")
data_tcellcd4_results <- readRDS("data/data_tcellcd4_results.rds")
data_tcellcd8_results <- readRDS("data/data_tcellcd8_results.rds")
data_nsclc_results <- readRDS("data/data_nsclc_results.rds")
#create pairwise lists
list_choices_names <- c("pbmc"="pbmc", "tcell_cd4"="tcell_cd4", "tcell_cd8"="tcell_cd8", "nsclc"="nsclc") #name-name
list_choices_names_dfs <- c("pbmc"=data_pbmc_results, "tcell_cd4"=data_tcellcd4_results, "tcell_cd8"=data_tcellcd8_results, "nsclc"=data_nsclc_results) #name-df
list_choices_names_descrip <- c("pbmc"="Peripheral blood mononuclear cells (PBMC) -- 10X Genomics \nhttps://support.10xgenomics.com/single-cell-gene-expression/datasets/1.1.0/pbmc3k",
"tcell_cd4"="CD4 T cells -- Zheng, G., Terry, J., Belgrader, P. et al. Massively parallel digital transcriptional profiling of single cells. Nat Commun 8, 14049 (2017).",
"tcell_cd8"="CD8 T cells -- Zheng, G., Terry, J., Belgrader, P. et al. Massively parallel digital transcriptional profiling of single cells. Nat Commun 8, 14049 (2017).",
"nsclc"="Non-small cell lung cancer -- 10X Genomics https://support.10xgenomics.com/single-cell-vdj/datasets/2.2.0/vdj_v1_hs_nsclc_5gex") #name-description
list_choices_filtering_criteria <- c("pbmc"="Quality control (filtering criteria) <ul><li>min.cells = 100: keep genes detected in at least 100 cells</li><li>min.features = 500: keep cells with at least 500 genes detected</li><li>percent.mt = 5: keep cells with less than 5% of genes mapping to mitochondrial genes</li></ul>",
"tcell_cd4"="Quality control (filtering criteria) <ul><li>min.cells = 100: keep genes detected in at least 100 cells</li><li>min.features = 500: keep cells with at least 500 genes detected</li><li>percent.mt = 5: keep cells with less than 5% of genes mapping to mitochondrial genes</li></ul>",
"tcell_cd8"="Quality control (filtering criteria) <ul><li>min.cells = 500: keep genes detected in at least 500 cells</li><li>min.features = 500: keep cells with at least 500 genes detected</li><li>percent.mt = 5: keep cells with less than 5% of genes mapping to mitochondrial genes</li></ul>",
"nsclc"="Quality control (filtering criteria) <ul><li>min.cells = 1000: keep genes detected in at least 1000 cells</li><li>min.features = 1000: keep cells with at least 1000 genes detected</li><li>percent.mt = 5: keep cells with less than 5% of genes mapping to mitochondrial genes</li></ul>") #name-description
#####tailored demo
#load datasets
data_pbmc_full <- readRDS("data/data_pbmc_full.rds")
data_tcellcd4_full <- readRDS("data/data_tcellcd4_full.rds")
data_tcellcd8_full <- readRDS("data/data_tcellcd8_full.rds")
data_nsclc_full <- readRDS("data/data_nsclc_full.rds")
#dataset list for selection
data_full_list <- list(pbmc="data_pbmc_full", tcell_cd4="data_tcellcd4_full", tcell_cd8="data_tcellcd8_full", nsclc="data_nsclc_full")
list_choices_names_dfs_tailored <- c("pbmc"=data_pbmc_full, "tcell_cd4"=data_tcellcd4_full, "tcell_cd8"=data_tcellcd8_full, "nsclc"=data_nsclc_full)
# one dataset (large dataset) pbmc -------------------------------------------------------------
#load datasets
# data_pbmc_results <- readRDS("data/data_pbmc_results.rds")
#
#
# #create pairwise lists
# list_choices_names <- c("pbmc"="pbmc") #name-name
# list_choices_names_dfs <- c("pbmc"=data_pbmc_results) #name-df
# list_choices_names_descrip <- c("pbmc"="Peripheral blood mononuclear cells (PBMC) -- 10X Genomics \nhttps://support.10xgenomics.com/single-cell-gene-expression/datasets/1.1.0/pbmc3k") #name-description
#
#
# #####tailored demo
# #load datasets
# data_pbmc_full <- readRDS("data/data_pbmc_full.rds")
#
#
# #dataset list for selection
# data_full_list <- list(pbmc="data_pbmc_full")
# list_choices_names_dfs_tailored <- c("pbmc"=data_pbmc_full) #name-df
# one dataset (large dataset) cd4 -------------------------------------------------------------
# #load datasets
# data_tcellcd4_results <- readRDS("data/data_tcellcd4_results.rds")
#
#
# #create pairwise lists
# list_choices_names <- c("tcell_cd4"="tcell_cd4") #name-name
# list_choices_names_dfs <- c("tcell_cd4"=data_tcellcd4_results) #name-df
# list_choices_names_descrip <- c("tcell_cd4"="CD4 T cells -- Zheng, G., Terry, J., Belgrader, P. et al. Massively parallel digital transcriptional profiling of single cells. Nat Commun 8, 14049 (2017).") #name-description
#
#
# #####tailored demo
# #load datasets
# data_tcellcd4_full <- readRDS("data/data_tcellcd4_full.rds")
#
#
# #dataset list for selection
# data_full_list <- list(tcell_cd4="data_tcellcd4_full")
# list_choices_names_dfs_tailored <- c("tcell_cd4"=data_tcellcd4_full) #name-df
# one dataset (small dataset) -------------------------------------------------------------
# #load datasets
# data_tcellcd4_results <- readRDS("data-small/data_tcellcd4_results.rds")
#
#
# #create pairwise lists
# list_choices_names <- c("tcell_cd4"="tcell_cd4") #name-name
# list_choices_names_dfs <- c("tcell_cd4"=data_tcellcd4_results) #name-df
# list_choices_names_descrip <- c("tcell_cd4"="CD4 T cells -- Zheng, G., Terry, J., Belgrader, P. et al. Massively parallel digital transcriptional profiling of single cells. Nat Commun 8, 14049 (2017).") #name-description
#
#
# #####tailored demo
# #load datasets
# data_tcellcd4_full <- readRDS("data-small/data_tcellcd4_full.rds")
#
#
# #dataset list for selection
# data_full_list <- list(tcell_cd4="data_tcellcd4_full")
# list_choices_names_dfs_tailored <- c("tcell_cd4"=data_tcellcd4_full) #name-df
# cloud data --------------------------------------------------------------
# #load datasets
# data_tcellcd4_results <- readRDS(url("https://vitessce-export-examples.s3.amazonaws.com/shiny-app/data_tcellcd4_results.rds"))
#
#
# #create pairwise lists
# list_choices_names <- c("tcell_cd4"="tcell_cd4") #name-name
# list_choices_names_dfs <- c("tcell_cd4"=data_tcellcd4_results) #name-df
# list_choices_names_descrip <- c("tcell_cd4"="CD4 T cells -- Zheng, G., Terry, J., Belgrader, P. et al. Massively parallel digital transcriptional profiling of single cells. Nat Commun 8, 14049 (2017).") #name-description
#
#
# #####tailored demo
# #load datasets
# data_tcellcd4_full <- readRDS(url("https://vitessce-export-examples.s3.amazonaws.com/shiny-app/data_tcellcd4_full.rds"))
#
#
# #dataset list for selection
# data_full_list <- list(tcell_cd4="data_tcellcd4_full")
# list_choices_names_dfs_tailored <- c("tcell_cd4"=data_tcellcd4_full) #name-df
# shiny app settings ------------------------------------------------------
options(shiny.maxRequestSize = 1000*1024^2) #limit file size to 500MB (for file upload)
# dynamic ui tabs ---------------------------------------------------------
tabs_input_data <- tabsetPanel(
id="tailored_demo_input_data",
type="hidden",
tabPanel("select_data",
selectInput("dataset_full", label="Select example dataset", choices=list_choices_names)
),
tabPanel("upload_data",
fileInput("user_dataset", "Upload dataset (SeuratObject in .rds file)", accept=".rds")
)
)
# ui panels ---------------------------------------------------------------
## basic demo -------------------------------------------------------------
### sidebarpanel ----------------------------------------------------------
basic_demo_sidebarpanel <- sidebarPanel(
#specify sidebarPanel features height, width, and scroll bar
width=3,
style = "position: fixed; height: 88.3vh; width: 42vh; overflow-y: auto;",
#1. select dataset from list of examples
h4("Dataset"),
selectInput("dataset", label=NULL, choices=list_choices_names),
#2. check dataset dimensions
h4("Dataset dimensions"),
htmlOutput("dataset_dimensions")
)
### mainpanel -------------------------------------------------------------
basic_demo_mainpanel <- mainPanel(
#create vitessce visualization
#h4("Vitessce visualization"),
vitessce_output(output_id="vitessce_visualization", height="700px", width="1030px")
)
## tailored demo ----------------------------------------------------------
### sidebarpanel ----------------------------------------------------------
#sidebarpanel
tailored_demo_sidebarpanel <- sidebarPanel(
#specify sidebarPanel features height, width, and scroll bar
width=3,
style = "position: fixed; height: 88.3vh; width: 42vh; overflow-y: auto;",
###1. specify dataset
h4("1. Specify dataset"),
#input data type: select dataset or upload dataset
selectInput(inputId="tailored_demo_input", label="Input data",
choices = c("Select example dataset"="select_data", "Upload dataset"="upload_data")
),
#based on input data type: drop-down list (select dataset) or data browser (upload dataset)
tabs_input_data,
###2. perform quality control
h4("2. Perform quality control (filter dataset)"),
numericInput("user_min_cells", HTML("min.cells<br><span style='font-weight:normal'>keep genes detected in at least <i>min.cells</i> cells</span>"), 1000, min=0, max=NA), #default value=100
numericInput("user_min_features", HTML("min.features<br><span style='font-weight:normal'>keep cells with at least <i>min.features</i> genes detected</span>"), 500, min=0, max=NA), #default value=500
numericInput("user_mt_gene_threshold", HTML("percent.mt<br><span style='font-weight:normal'>keep cells with less than <i>percent.mt</i>% of genes mapping to mitochondrial genes</span>"), 5, min=0, max=100), #default value=5
###3. check dataset dimensions
h4("3. Check dataset dimensions"),
htmlOutput("dataset_dimensions_tailored"),
###4. specify vitessce visualization parameters
h4("4. Specify Vitessce visualization parameters"),
#row1: analyses and summaries
fluidRow(
column(6, checkboxGroupInput("checkboxes_analyses", label="Analyses",
choices=list("PCA"="pca", "UMAP"="umap", "t-SNE"="tsne"),
selected=c("pca", "umap", "tsne"))
),
column(6, checkboxGroupInput("checkboxes_summaries", label="Summaries",
choices=list("Heatmap"="heatmap", "Cell set sizes"="cell_set_sizes"),
selected=c("heatmap", "cell_set_sizes"))
),
), #end fluidRow (row1)
#row2: description and view options
fluidRow(
column(6, checkboxGroupInput("checkboxes_descrip", label="Descriptions",
choices=list("Dataset"="dataset_descrip", "Cell sets"="cell_sets", "Genes"="genes"),
selected=c("dataset_descrip", "cell_sets", "genes"))
),
column(6, checkboxGroupInput("checkboxes_view", label="View options",
choices=list("Link scatterplots"="link_scatterplots", "Light theme"="light_theme"),
selected=c("link_scatterplots", "light_theme"))
),
) #end fluidRow (row2)
) #end sidebarPanel (end tailored_demo_sidebarpanel)
### mainpanel -------------------------------------------------------------
#main panel
tailored_demo_mainpanel <- mainPanel(
#h4("Vitessce visualization"),
vitessce_output(output_id="vitessce_visualization_tailored", height="700px", width="1030px")
)
# ui ----------------------------------------------------------------------
# ui <- fluidPage(
# sidebarLayout(
# tailored_demo_sidebarpanel,
# tailored_demo_mainpanel
# )
# )
ui <- navbarPage(
"Vitessce Shiny",
##### ui: basic demo ----------------------------------------------------
tabPanel(
"Demo",
fluidPage(
sidebarLayout(basic_demo_sidebarpanel, basic_demo_mainpanel)
) #end fluidPage
), #end tabPanel
##### ui: tailored demo -------------------------------------------------
tabPanel("Run analysis",
fluidPage(
sidebarLayout(tailored_demo_sidebarpanel, tailored_demo_mainpanel)
) #end fluidPage
) #end tabPanel
) #end navbarPage (end ui)
# server ------------------------------------------------------------------
#OUT_DIR <- "/Users/than/Dropbox/ddesktop/lab-gehlenborg/vitessce-shiny/my_vitessce_files"
OUT_DIR <- "./my_vitessce_files"
server <- function(input, output, session){
addResourcePath("my-processed-data", OUT_DIR)
## basic demo -------------------------------------------------------------
###1. get data (based on selected dataset in input)
data <- reactive({list_choices_names_dfs[[input$dataset]]}) #get dataset
data_filtering_criteria <- reactive({list_choices_filtering_criteria[[input$dataset]]})
data_descrip <- reactive({list_choices_names_descrip[[input$dataset]]}) #get dataset description
###2. print dimensions of dataset
output$dataset_dimensions <- renderUI({
dim(data())
#str_criteria <- "Quality control (filtering criteria) <ul><li>min.cells = 100: keep genes detected in at least 100 cells</li><li>min.features = 500: keep cells with at least 500 genes detected</li><li>percent.mt = 5: keep cells with less than 5% of genes mapping to mitochondrial genes</li></ul>"
str_criteria <- data_filtering_criteria() #string: dataset filtering criteria
str_dim_data <- paste("Dataset dimensions:", dim(data())[1], "genes x", dim(data())[2], "cells") #string: dataset dimensions
HTML(paste(str_criteria, str_dim_data, sep=""))
})
###3. vitessce visualization
output$vitessce_visualization <- render_vitessce(expr={
#create progress object
progress <- shiny::Progress$new()
progress$set(message = "", value = 0)
on.exit(progress$close()) #close the progress bar when this reactive exits
#function to update progress
n <- 3
updateProgress <- function(detail = NULL){
progress$inc(amount = 1/n, detail = detail)
}
#vitessce --- set up widget
updateProgress("Demo: creating individual visualizations")
vc <- VitessceConfig$new("My config")
dataset <- vc$add_dataset("My dataset")
dataset <- dataset$add_object(SeuratWrapper$new(data(),
cell_set_meta_names=list("seurat_clusters"),
num_genes=100,
out_dir=OUT_DIR))
#vitessce --- add views (panels)
panel_scatterplot_pca <- vc$add_view(dataset, Component$SCATTERPLOT, mapping="pca")
panel_scatterplot_umap <- vc$add_view(dataset, Component$SCATTERPLOT, mapping="umap")
panel_scatterplot_tsne <- vc$add_view(dataset, Component$SCATTERPLOT, mapping="tsne")
panel_heatmap <- vc$add_view(dataset, Component$HEATMAP)
#panel_status <- vc$add_view(dataset, Component$STATUS)
panel_cellsets <- vc$add_view(dataset, Component$CELL_SETS)
panel_cellset_sizes <- vc$add_view(dataset, Component$CELL_SET_SIZES)
panel_genes <- vc$add_view(dataset, Component$GENES)
panel_description <- vc$add_view(dataset, Component$DESCRIPTION)
panel_description <- panel_description$set_props(description=data_descrip())
updateProgress("Demo: assembling Vitessce visualization")
vc$layout(hconcat(vconcat(panel_scatterplot_pca, panel_scatterplot_umap, panel_scatterplot_tsne),
vconcat(panel_heatmap, panel_cellset_sizes),
vconcat(panel_description,
#panel_status,
panel_cellsets, panel_genes)))
#vitessce --- link scatterplots
vc$link_views(
c(panel_scatterplot_pca, panel_scatterplot_umap, panel_scatterplot_tsne),
c(CoordinationType$EMBEDDING_ZOOM, CoordinationType$EMBEDDING_TARGET_X, CoordinationType$EMBEDDING_TARGET_Y),
c_values = c(1, 0, 0)
)
#update progress bar
updateProgress("Demo: complete!")
#vitessce --- specify theme
BASE_URL <- paste0(session$clientData$url_protocol,
"//",
session$clientData$url_hostname,
":",
session$clientData$url_port,
#"/my-processed-data"
"/vitessce-shiny/my-processed-data"
)
#vc$widget(theme="light")
vc$widget(theme="light", serve=FALSE, base_url=BASE_URL)
}) #end vitessce visualization output
## tailored demo ----------------------------------------------------------
###1. obtain full dataset
#based on input$tailored_demo_input: selected dataset or uploaded dataset
observeEvent(input$tailored_demo_input, {
updateTabsetPanel(inputId="tailored_demo_input_data", selected=input$tailored_demo_input)
})
#create data_full() reactive by getting selected dataset or loading uploaded dataset
data_full <- reactive({
switch(input$tailored_demo_input,
select_data=list_choices_names_dfs_tailored[[input$dataset_full]],
upload_data=readRDS(input$user_dataset$datapath)
)
})
#create data_descrip_tailored() reactive to get dataset descriptionn
data_descrip_tailored <- reactive({
switch(input$tailored_demo_input,
select_data=list_choices_names_descrip[[input$dataset_full]],
upload_data="My data"
)
})
###2. perform quality control: filter dataset
expr_matrix_subset <- reactive({
GetAssayData(object=data_full(), slot="data")
})
data_subset <- reactive({
data_subset_genes_and_cells <- CreateSeuratObject(counts=expr_matrix_subset(), project="subset", min.cells=input$user_min_cells, min.features=input$user_min_features) #subset data based on min.cells and min.features (user_min_cells and user_min_features)
data_subset_genes_and_cells[["percent.mt"]] <- PercentageFeatureSet(data_subset_genes_and_cells, pattern="^MT-") #add mitochondrial genes column
data_subset_mt_genes <- subset(data_subset_genes_and_cells, subset=percent.mt<input$user_mt_gene_threshold) #subset data based on mitochondrial genes (user_mt_gene_threshold)
})
###3. print dataset dimensions
output$dataset_dimensions_tailored <- renderUI({
str_dim_data_full <- paste("<b>Full dataset</b><br>", dim(data_full())[1], "genes x ", dim(data_full())[2], "cells<br> ")
str_dim_data_subset <- paste("<b>Subsetted dataset</b><br>", dim(data_subset())[1], "genes x ", dim(data_subset())[2], "cells<br> <br>")
#print dimensions
HTML(paste(str_dim_data_full, str_dim_data_subset, sep="<br/>"))
})
###4. create Vitessce visualization
#analyze data
data_tailored <- reactive({
analyze_data(data_subset())
})
#vitessce visualization
output$vitessce_visualization_tailored <- render_vitessce(expr={
#create progress object
progress <- shiny::Progress$new()
progress$set(message="", value=0)
on.exit(progress$close()) #close the progress bar when this reactive exits
#function to update progress
n <- 3
updateProgress <- function(detail = NULL){
progress$inc(amount = 1/n, detail = detail)
}
#vitessce --- set up widget
updateProgress("Analysis: creating individual visualizations")
vc <- VitessceConfig$new("My config")
dataset <- vc$add_dataset("My dataset")
dataset <- dataset$add_object(SeuratWrapper$new(data_tailored(),
cell_set_meta_names=list("seurat_clusters"),
num_genes=100,
out_dir = OUT_DIR))
###create reactives based on inputs
#reactive: panels, analyses (column 1)
reactive_column_analyses <- reactive({
column_panels <- c()
if("pca" %in% input$checkboxes_analyses){
panel_scatterplot_pca <- vc$add_view(dataset, Component$SCATTERPLOT, mapping="pca")
column_panels <- append(column_panels, panel_scatterplot_pca)
}
if("umap" %in% input$checkboxes_analyses){
panel_scatterplot_umap <- vc$add_view(dataset, Component$SCATTERPLOT, mapping="umap")
column_panels <- append(column_panels, panel_scatterplot_umap)
}
if("tsne" %in% input$checkboxes_analyses){
panel_scatterplot_tsne <- vc$add_view(dataset, Component$SCATTERPLOT, mapping="tsne")
column_panels <- append(column_panels, panel_scatterplot_tsne)
}
column_panels
})
#reactive: panels, summaries (column 2)
reactive_column_summaries <- reactive({
column_panels <- c()
if("heatmap" %in% input$checkboxes_summaries){
panel_heatmap <- vc$add_view(dataset, Component$HEATMAP)
column_panels <- append(column_panels, panel_heatmap)
}
if("cell_set_sizes" %in% input$checkboxes_summaries){
panel_cellset_sizes <- vc$add_view(dataset, Component$CELL_SET_SIZES)
column_panels <- append(column_panels, panel_cellset_sizes)
}
column_panels
})
#reactive: panels, description (column 3)
reactive_column_descrip <- reactive({
column_panels <- c()
if("dataset_descrip" %in% input$checkboxes_descrip){
panel_description <- vc$add_view(dataset, Component$DESCRIPTION)
panel_description <- panel_description$set_props(description=data_descrip_tailored())
column_panels <- append(column_panels, panel_description)
}
if("cell_sets" %in% input$checkboxes_descrip){
panel_cellsets <- vc$add_view(dataset, Component$CELL_SETS)
column_panels <- append(column_panels, panel_cellsets)
}
if("genes" %in% input$checkboxes_descrip){
panel_genes <- vc$add_view(dataset, Component$GENES)
column_panels <- append(column_panels, panel_genes)
}
column_panels
})
updateProgress("Analysis: assembling Vitessce visualization")
#reactive: view options, link or unlink scatterplots
reactive_link_scatterplots <- reactive({
#link scatterplots
if("link_scatterplots" %in% input$checkboxes_view){
vc$link_views(reactive_column_analyses(),
c(CoordinationType$EMBEDDING_ZOOM, CoordinationType$EMBEDDING_TARGET_X, CoordinationType$EMBEDDING_TARGET_Y),
c_values=c(1, 0, 0)
)
} #end "if" statement
#unlink scatterplots
else{
for(view in reactive_column_analyses()){
vc$link_views(c(view),
c(CoordinationType$EMBEDDING_ZOOM, CoordinationType$EMBEDDING_TARGET_X, CoordinationType$EMBEDDING_TARGET_Y),
c(1, 0, 0)
)
} #end for loop: for(view in reactive_column_analyses())
} #end "else" statement
}) #end reactive: reactive_link_scatterplots
#reactive: view options, light or dark theme
reactive_light_theme <- reactive({
BASE_URL <- paste0(session$clientData$url_protocol,
"//",
session$clientData$url_hostname,
":",
session$clientData$url_port,
#"/my-processed-data"
"/vitessce-shiny/my-processed-data"
)
#light theme
if("light_theme" %in% input$checkboxes_view){vc$widget(theme="light", serve=FALSE, base_url=BASE_URL)}
#dark theme
else{vc$widget(theme="dark", serve=FALSE, base_url=BASE_URL)}
})
#panel_columns: list of columns (in Vitessce visualization) that are not empty
panel_columns <- list(analyses=reactive_column_analyses(), summaries=reactive_column_summaries(), descrip=reactive_column_descrip())
#return error message if no panels (visualizations) are selected
empty_visualization <- reactive({length(reactive_column_analyses())==0 & length(reactive_column_summaries())==0 & length(reactive_column_descrip())==0})
validate(need(!empty_visualization(), "Please select at least one visualization"))
#remove list of columns (reactive_column_analyses, reactive_column_summaries, and reactive_column_descrip) that are empty
if(length(reactive_column_analyses())==0){panel_columns <- within(panel_columns, rm(analyses))}
if(length(reactive_column_summaries())==0){panel_columns <- within(panel_columns, rm(summaries))}
if(length(reactive_column_descrip())==0){panel_columns <- within(panel_columns, rm(descrip))}
#apply do.call(vconcat) to every list (make as list) in panel_columns
panel_columns_vconcat <- lapply(panel_columns, function(x){do.call(vconcat, as.list(x))})
#apply do.call(hconcat) to the list 'panel_columns_vconcat'
panel_columns_hconcat <- do.call(hconcat, panel_columns_vconcat)
#vitessce --- add views: create/update columns and panels
vc$layout(panel_columns_hconcat)
# #vitessce --- add views: use reactives to create/update/layout columns and panels
# vc$layout(hconcat(do.call(vconcat, as.list(reactive_column_analyses())),
# do.call(vconcat, as.list(reactive_column_summaries())),
# do.call(vconcat, as.list(reactive_column_descrip()))
# )
# )
#vitessce --- link or unlink scatterplots
reactive_link_scatterplots()
#update progress bar
updateProgress("Analysis: complete!")
#vitessce --- specify theme (light or dark)
reactive_light_theme()
}) #end vitessce visualization
} #end server
# compile app -------------------------------------------------------------
shinyApp(ui=ui, server=server)