-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.R
executable file
·852 lines (764 loc) · 33.3 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
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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
load("shiny_input.RData")
shinyServer(function(input, output, session) {
# define default selection
rv <- reactiveValues(
# for tab "Metabolites" and others
go1 = 0,
# for tab "Kit Overview"
go2 = 0,
selected.performance = FALSE
)
# Data & UI: Switch between data sets -------------------------------------
# Reactive:
# input$data_set
#
# Input:
# input_df_cells
#
# input_df_organisms
#
# Output:
# rv$input_df
# rv$table_df
#
# rv$selected.methods
# rv$selected.tissues
# rv$selected.method
# rv$selected.tissue
observeEvent(input$data_set, {
if (input$data_set == "cells") {
## input_df
rv$input_df <- input_df_cells %>%
ungroup() %>%
group_by(Tissue, Class, Metabolite, Method, Methods, Mean, CV,
Group, LOD) %>%
dplyr::summarise()
## table_df
rv$table_df <- input_df_cells %>%
ungroup() %>%
select(Metabolite, Methods, Tissue, Class, Replicate, Concentration,
LOD, CV, Sum) %>%
rename(Method = Methods)
## conc_df
rv$conc_df <- input_df_cells %>%
ungroup %>%
select(Tissue, Class, Metabolite, Method, Methods, Concentration,
Group, CV)
} else if (input$data_set == "organisms") {
## input_df
rv$input_df <- input_df_organisms %>%
ungroup() %>%
group_by(Tissue, Class, Metabolite, Method, Methods, Mean, CV,
Group, LOD) %>%
dplyr::summarise()
## table_df
rv$table_df <- input_df_organisms %>%
ungroup() %>%
select(Metabolite, Methods, Tissue, Class, Replicate, Concentration,
LOD, CV, Sum) %>%
rename(Method = Methods)
## conc_df
rv$conc_df <- input_df_organisms %>%
ungroup %>%
select(Tissue, Class, Metabolite, Method, Methods, Concentration,
Group, CV)
}
## default selection
rv$selected.methods <- unique(rv$input_df$Methods) # for input$methods
rv$selected.tissues <- unique(rv$input_df$Tissue) # for input$tissues
rv$selected.method <- unique(rv$input_df$Methods)[1] # for input$method
rv$selected.tissue <- unique(rv$input_df$Tissue)[1] # for input$tissue
})
# Reactive:
# rv$initial.calc1
# rv$go1
#
# Input:
# col_vector_methods_cells
# col_vector_tissues_cells
#
# col_vector_methods_organisms
# col_vector_tissues_organisms
#
# Output:
#
# rv$col_vector_methods
# rv$col_vector_tissue
observeEvent(c(rv$initial.calc1, rv$go1), {
if (input$data_set == "cells") {
## color vectors
rv$col_vector_methods <- col_vector_methods_cells
rv$col_vector_tissue <- col_vector_tissues_cells
} else if (input$data_set == "organisms") {
## color vectors
rv$col_vector_methods <- col_vector_methods_organisms
rv$col_vector_tissue <-col_vector_tissues_organisms
}
})
# UI: Sidebar input depending on tab --------------------------------------
# Reactive:
# input$tabs
# input$sub_tabs
observeEvent(c(input$tabs, input$sub_tabs), {
if (input$tabs == "Concentration") {
# Select LOD is disabled for tab "Concentration"
output$selectLOD <- NULL
} else {
# Select LOD
output$selectLOD <- renderUI({
radioButtons("lod",
label = h3("Filter based on LOD"),
choices = list("Yes" = 0, "No" = "dummy"),
selected = c(0))
})
}
if (input$tabs == "Concentration" & input$sub_tabs == "Single view") {
# Output:
# input$tissue
# input$method
# input$bestPerformance
# input$applyFilters2
# Single tissue
output$tissuesInput <- renderUI({
radioButtons("tissue",
label = h3("Select tissue"),
choices = unique(rv$input_df$Tissue),
selected = rv$selected.tissue)
})
# Single method
output$methodsInput <- renderUI({
selectizeInput("method",
label = h3("Select method"),
choices = unique(rv$input_df$Methods),
selected = rv$selected.method,
multiple = FALSE,
options = NULL)
})
# Performance selection
output$bestSelection <- renderUI({
radioButtons("bestPerformance",
label = "",
choices = list("Selected method performs best" = TRUE,
"Selected method performs not optimal" = FALSE),
selected = rv$selected.performance)
})
# Action button ID
actionID <- "applyFilters2"
} else {
# Output:
# input$tissues
# input$methods
# input$applyFilters
# Multiple tissues
output$tissuesInput <- renderUI({
checkboxGroupInput("tissues",
label = h3("Select tissues"),
choices = as.list(as.character(unique(rv$input_df$Tissue))),
selected = rv$selected.tissues)
})
# Multiple methods
output$methodsInput <- renderUI({
selectizeInput("methods",
label = h3("Select methods"),
choices = unique(rv$input_df$Methods),
selected = rv$selected.methods,
multiple = TRUE,
options = NULL)
})
# Performance selection
output$bestSelection <- NULL
# Action button ID
actionID <- "applyFilters1"
}
# Render action button
output$calcInput <- renderUI({
actionButton(inputId = actionID,
label = tags$strong("Apply filters"),
width = "100%",
style="color: #fff;
background-color: #337ab7;
border-color: #2e6da4")
})
})
# UI: Sidebar input depending on dataset ----------------------------------
# Reactive:
# rv$input_df
observeEvent(rv$input_df, {
req(rv$input_df)
output$selectCV <- renderUI({
sliderInput("cv",
h3("Select CV limit"),
value = 0.5,
min = 0,
max = signif(max(rv$input_df$CV, na.rm = TRUE), 3) + 0.02)
})
})
# UI: Show Kit Overview ---------------------------------------------------
# Reactive:
# input$kit_overview
observeEvent(input$kit_overview, {
updateTabsetPanel(session, "tabs", selected = "Kit Overview")
})
# Reactive: Trigger reactive calculation ----------------------------------
# Action buttons counter will be reset to 0 each time they are newly rendered
# (when changing the tab). An extra counter won't be reset and only triggers
# new calculation when really needed
observeEvent(input$applyFilters1, {
rv$go1 <- rv$go1 + 1
})
observeEvent(input$applyFilters2, {
rv$go2 <- rv$go2 + 1
})
# trigger initial calculation after reactive UI has been rendered
observe({
req(input$tissues, input$methods)
rv$initial.calc1 <- 1
})
observe({
req(input$tissue, input$method, input$bestPerformance)
rv$initial.calc2 <- 1
})
# UI: Save selection for different tabs -----------------------------------
observeEvent(rv$go1, {
req(input$tissues, input$methods)
rv$selected.methods <- input$methods
rv$selected.tissues <- input$tissues
})
observeEvent(rv$go2, {
req(input$tissue, input$method, input$bestPerformance)
rv$selected.method <- input$method
rv$selected.tissue <- input$tissue
rv$selected.performance <- input$bestPerformance
})
# UI: Help text -----------------------------------------------------------
observeEvent(input$help, {
output$help.text_met <- renderUI({
if (input$help) {
return(
fluidRow(
column(
width = 12,
HTML("This ShinyApp allows to explore ten extraction
methods for metabolic measurements of four
human tissues or cell lines (liver, bone
marrow, HEK and HL-60) using the Biocrates MxP
500 Quant Kit.<br><br>
Check out the reference publication for detailed
information and extraction protocols.<br><br>
Tissues, methods and classes of metabolites can
be (de)selected to focus on the data of interest
and the maximal coefficient of variation (CV)
between triplicates can be chosen.
Additionally, values below the limit of
detection (LOD) can be included. Though it is
highly recommended to use the LOD for
filtering.<br><br>"),
# HTML("<p><img src="Extraction.png"/></p><br><br>"),
HTML("<b>Overview:</b><br><br>"),
renderTable(data.frame("Tab" = c("Statistics",
"Concentration",
"Spectra",
"Replicates",
"Table",
"Kit Overview"),
"Content" = c("explore the number of detectable metabolites
and the variablity between triplicates",
"explore which extraction methods allows to detect the
highest concentrations",
"explore the metabolite concentrations across
methods and tissue types",
"explore global variation between technical
replicates",
"explore and download raw data",
"explore the metabolites and classes of metabolites
which are covered by the Biocrates MxP 500 Quant Kit")))
)
)
)
}
})
output$help.text_stat_1 <- renderUI({
if (input$help) {
return(
fluidRow(
column(
width = 12,
HTML("Note: the number depends on CV and LOD
settings. Some metabolites are not detected
at all.")
)
)
)
}
})
output$help.text_stat_2 <- renderUI({
if (input$help) {
return(
fluidRow(
column(
width = 12,
HTML("Note: the number depends on CV and LOD
settings. Some metabolites are not detected
all.")
)
)
)
}
})
output$help.text_spec_1 <- renderUI({
if (input$help) {
return(
fluidRow(
column(
width = 12,
HTML("Note: concentrations are displayed in log
scale. Concentrations are either
given as pmol/10<sup>6</sup> cells (HEK,
HL-60 and bone marrow) or pmol/mg (liver).")
)
)
)
}
})
output$help.text_rep_1 <- renderUI({
if (input$help) {
return(
fluidRow(
column(
width = 12,
HTML("Note: MeOH/ChCl2-HEK was measured in
duplicates due to quality-based filtering.")
)
)
)
}
})
output$help.text_table_1 <- renderUI({
if (input$help) {
return(
fluidRow(
column(
width = 12,
HTML("Choose option to download table.")
)
)
)
}
})
output$help.text_conc <- renderUI({
if (input$help) {
return(
fluidRow(
column(
width = 12,
HTML("Optimal extraction methods were determined for
each metabolite based on the measured concentration.
The method with the highest median yield was
considered optimal. This method is labeled with an
"A" (refer to "Single view").
Other methods with non-significantly lower
concentrations were also taken into account and
given an "A" in their labeling among
other letters. All other methods were considered
non-optimal and labeled with consecutive letters.
The dotted line shows the number of detectable
metabolites for each sample type.
<br><br>Note: LOD filtering is disabled for this
tab since it is already included in the
statistical analysis. Metabolites where values of
all methods are below LOD were therefore excluded.<br>
CV filtering in \"Single view\" is only applied to
the selected method.")
)
)
)
}
})
})
# Data: Filter input_df ---------------------------------------------------
# Reactive:
# rv$initial.calc1
# rv$go1
prefiltered_input_df <- eventReactive(c(rv$initial.calc1, rv$go1), {
req(input$tissues, input$methods)
temp_input_df <- rv$input_df %>%
filter(CV <= input$cv,
Tissue %in% input$tissues,
Methods %in% input$methods,
Class %in% input$class) %>%
droplevels()
temp_input_df
})
filtered_input_df <- reactive({
filter(prefiltered_input_df(), LOD != input$lod)
})
# Tab: Statistics ---------------------------------------------------------
# Barplot showing number of metabolites above LOD
bar_input_df <- reactive({
group_by(filtered_input_df(), Methods, Class, Tissue) %>%
dplyr::summarise(Number = n()) %>%
data.frame()
})
output$detec_metabo <- renderPlotly({
print(ggplotly(ggplot(bar_input_df(),
aes(x = Methods, y = Number, fill = Class)) +
geom_bar(stat = "identity") +
scale_fill_manual(values = col_vector_classes) +
theme_light() +
theme(legend.position = "bottom",
axis.text.x = element_text(angle = 45,
hjust = 1,
size = 8)) +
xlab("") +
facet_grid(~ Tissue)))
})
# Summary plot
sum_input_df <- reactive({
tmp_df <- filtered_input_df() %>%
group_by(Tissue, Methods) %>%
dplyr::summarise(Number_Metabolites = n(),
Median_CV = median(CV, na.rm = TRUE),
MAD_CV = mad(CV, na.rm = TRUE)) %>%
data.frame()
tmp_df
})
output$sum_detec_metabo <- renderPlotly({
print(ggplotly(ggplot(sum_input_df(), aes(Methods, Number_Metabolites)) +
geom_bar(aes(fill = Tissue), position = "dodge",
stat="identity") +
xlab("") +
ylab("Number") +
theme_light() +
theme(legend.position = "bottom",
axis.text.x = element_text(angle = 45,
hjust = 1)) +
scale_fill_manual(values = rv$col_vector_tissue)
# ylim(0, 500)
))
})
# CV plot
output$CV_dist <- renderPlotly({
print(ggplotly(ggplot(filtered_input_df(), aes(CV)) +
geom_histogram(aes(fill = Tissue), alpha = 0.5,
position = "identity", binwidth = 0.05) +
facet_wrap(~ Methods, ncol = 2, strip.position = "right") +
# ggtitle("All metabolites") +
theme_bw() +
theme(strip.text.y = element_text(angle = 270, size = 6)) +
scale_fill_manual(values = rv$col_vector_tissue) +
ylab("")))
})
output$var_CV <- renderPlotly({
print(ggplotly(ggplot(sum_input_df(), aes(Methods, Median_CV)) +
geom_bar(aes(fill = Tissue),
position = "dodge",
stat = "identity") +
geom_errorbar(aes(ymin = Median_CV,
ymax = Median_CV+MAD_CV,
group = Tissue),
width = .2,
position = position_dodge(.9),
col = "black") +
xlab("") +
ylab("Median CV + MAD") +
theme_light() +
theme(legend.position = "bottom",
axis.text.x = element_text(angle = 45,
hjust = 1)) +
scale_fill_manual(values = rv$col_vector_tissue)))
})
# Tab: Concentration ------------------------------------------------------
# Barplot showing number of metabolites for best extraction method
high_yield_df <- reactive({
temp_input_df <- prefiltered_input_df() %>%
filter(!is.na(Group)) %>%
droplevels() %>%
group_by(Methods, Class, Tissue) %>%
dplyr::summarise(Number = length(grep("A", Group))) %>%
data.frame()
temp_input_df
})
max_metabolites <- reactive({
prefiltered_input_df() %>%
filter(!is.na(Group)) %>%
group_by(Tissue) %>%
summarise(max = length(unique(Metabolite)))
})
output$bar_high_yield <- renderPlotly({
print(ggplotly(ggplot(high_yield_df(),
aes(x = Methods, y = Number, fill = Class)) +
geom_bar(stat = "identity") +
geom_hline(data=max_metabolites(),
aes(yintercept=max), linetype = 2) +
scale_fill_manual(values = col_vector_classes) +
theme_light() +
theme(legend.position = "bottom",
axis.text.x = element_text(angle = 45,
hjust = 1,
size = 8)) +
xlab("") +
facet_grid(~ Tissue)))
})
# Concentration boxplots
observeEvent(c(rv$initial.calc2, rv$go2), {
req(input$tissue, input$method, input$bestPerformance)
rv$plot_index <- 1 # refresh index for new input
rv$ylab <- ifelse(input$tissue %in% c("HEK", "HL60", "Bone Marrow"),
"Concentration [pmol/10^6 cells]",
"Concentration [pmol/mg tissue]")
temp_conc_df <- rv$conc_df %>%
filter(Tissue == input$tissue,
Class %in% input$class,
!is.na(Group)) %>%
droplevels()
tmp_df <- temp_conc_df %>%
filter(CV <= input$cv,
Methods == input$method) %>%
select(-c(Concentration)) %>%
droplevels() %>%
distinct()
metabolites <- tmp_df$Metabolite[grep("A", tmp_df$Group, invert = !as.logical(input$bestPerformance))]
if (length(metabolites) == 0) {
rv$s <- 0
rv$e <- 0
rv$max_len <- 0
rv$box_input_df <- NULL
} else {
plot_data <- temp_conc_df %>%
filter(Metabolite %in% metabolites) %>%
group_by(Metabolite, Method) %>%
mutate(LabelPos = max(Concentration)) %>%
group_by(Metabolite) %>%
mutate(LabelPos = LabelPos + 0.1*max(Concentration)) %>%
select(Metabolite, Method, Methods, Concentration, Group, LabelPos)
rv$max_len <- length(unique(plot_data$Metabolite))
rv$box_input_df <- plot_data
}
# update colors
if (input$data_set == "cells") {
## color vectors
rv$col_vector_methods <- col_vector_methods_cells
rv$col_vector_tissue <- col_vector_tissues_cells
} else if (input$data_set == "organisms") {
## color vectors
rv$col_vector_methods <- col_vector_methods_organisms
rv$col_vector_tissue <-col_vector_tissues_organisms
}
})
observeEvent(input$next6, {
max_index <- ceiling(rv$max_len / 6)
if (rv$plot_index < max_index) {
rv$plot_index <- rv$plot_index + 1
}
})
observeEvent(input$previous6, {
if (rv$plot_index > 1) {
rv$plot_index <- rv$plot_index - 1
}
})
box_input_sub <- eventReactive(c(rv$plot_index, rv$go2), {
req(rv$box_input_df)
rv$s <- (rv$plot_index - 1) * 6 + 1
rv$e <- rv$plot_index * 6
if (rv$e > rv$max_len) {
rv$e <- rv$max_len
}
if (rv$e - rv$s == 0) {
# only 1 plot
rv$width <- "60%"
rv$ncol <- 1
} else {
rv$width <- "100%"
rv$ncol <- 2
}
rv$nrow <- ceiling((rv$e-rv$s+1) / 2)
rv$height <- paste0(160 + rv$nrow * 180, "px")
out <- filter(rv$box_input_df,
Metabolite %in% unique(rv$box_input_df$Metabolite)[rv$s:rv$e])
return(out)
})
output$plot_numbers <- renderUI({
req(rv$s, rv$e, rv$max_len)
if (rv$s < rv$e) {
return(HTML(paste("<h5>Showing plots<b>", rv$s, "</b>to<b>", rv$e,
"</b><br>The total number of plots is<b>",
rv$max_len, "</b></h5>")))
} else {
return(HTML(paste("<h5>Showing plot<b>", rv$s,
"</b><br>The total number of plots is<b>",
rv$max_len, "</b></h5>")))
}
})
output$box_plots <- renderPlotly({
print(ggplotly(ggplot(box_input_sub(),
aes(x = Methods, y = Concentration, fill = Methods)) +
geom_boxplot() +
scale_fill_manual(values = rv$col_vector_methods) +
geom_text(data = box_input_sub() %>%
group_by(Metabolite, Methods) %>%
dplyr::summarise(Group = unique(Group),
LabelPos = unique(LabelPos)),
aes(x = Methods, y = LabelPos, label = Group),
# position = position_dodge(width = 0.9),
) +
theme_light() +
theme(legend.position = "bottom",
axis.text.x = element_text(angle = 45,
hjust = 1,
size = 8),
plot.margin = unit(c(0, 5, 0, 20), "pt")) +
xlab("") +
ylab(rv$ylab) +
facet_wrap(~ Metabolite, scales="free_y",
nrow = rv$nrow, ncol = rv$ncol),
tooltip = "text") %>%
style(hoverinfo = "none", traces = 1))
})
output$box_plots_UI <- renderUI({
plotlyOutput("box_plots", height = rv$height, width = rv$width) %>%
withSpinner(color="#428bca")
})
# Tab: Spectra ------------------------------------------------------------
y_lab <- eventReactive(c(rv$initial.calc1, rv$go1), {
ifelse(input$data_set == "cells",
expression(paste("Mean Concentration [pmol/mg] or [pmol/", 10^6, " cells]")),
"Mean Concentration [pmol/mg]")
})
output$spectra <- renderPlot({
ggplot(filtered_input_df(), aes(x = Metabolite, y = Mean, fill = Class)) +
geom_bar(stat = "identity") +
scale_fill_manual(values = col_vector_classes) +
facet_grid(Methods ~ Tissue) +
theme_bw() +
scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x))) +
ylab(y_lab()) +
theme(axis.text.x = element_blank(),
axis.ticks.length.x = unit(0, "cm"),
panel.grid.major= element_line(color = "white"),
panel.grid.minor.y = element_blank(),
strip.text.y = element_text(angle = 270, size = 8.5),
strip.text.x = element_text(size = 10),
legend.position = "bottom")
})
# Tab: Replicates ---------------------------------------------------------
rep_input_df <- reactive({
temp_input_df <- filtered_table_df() %>%
ungroup() %>%
select(c(Tissue, Method, Replicate, Sum)) %>%
distinct() %>%
mutate(Replicate = paste0("R", Replicate)) %>%
arrange(Tissue, Method, Replicate)
temp_input_df
})
output$bar_replicates <- renderPlot({
suppressWarnings(print(ggplot(rep_input_df(), aes(x = Tissue,
y = Sum,
fill = Replicate)) +
geom_bar(position = "dodge",
stat = "identity") +
facet_wrap(~ Method, ncol = 2) +
theme_bw() +
ylab("Sum of concentrations") +
xlab("") +
scale_fill_manual(values = c("grey40",
"grey60",
"grey80"))))
})
# Replicate table
output$rep_table <- DT::renderDataTable(
rep_input_df(),
rownames= FALSE,
server = FALSE,
selection = "none",
options = list(dom = "Blfrtip",
buttons = c("copy", "excel", "pdf")),
extensions = "Buttons"
)
# Tab: Tables -------------------------------------------------------------
observeEvent(c(rv$initial.calc1, rv$go1), {
if (input$data_set == "cells") {
output$table_title <- renderUI({
HTML("<h4>Metabolite concentrations are either given as
pmol/10<sup>6</sup> cells (HEK, HL-60 and bone marrow) or
pmol/mg (liver).</h4>")
})
} else {
output$table_title <- renderUI({
HTML("<h4>Metabolite concentrations are given as pmol/mg.</h4>")
})
}
})
# Prep raw data table
filtered_table_df <- eventReactive(c(rv$initial.calc1, rv$go1), {
req(input$tissues, input$methods)
if (input$cv == signif(max(rv$input_df$CV, na.rm = TRUE), 3) + 0.02) {
temp_input_df <- rv$table_df %>%
filter(LOD != input$lod,
CV <= input$cv,
Tissue %in% input$tissues,
Method %in% input$methods,
Class %in% input$class) %>%
droplevels()
} else {
temp_input_df <- rv$table_df %>%
filter(LOD != input$lod,
CV <= input$cv,
Tissue %in% input$tissues,
Method %in% input$methods,
Class %in% input$class) %>%
droplevels()
}
temp_input_df <- temp_input_df %>%
dplyr::select(c(Tissue, Method, Class, Metabolite,
Replicate, Concentration, Sum)) %>%
arrange(Tissue, Method, Class, Metabolite, Replicate)
temp_input_df})
# Generate a summary of the data
output$data_sum_table <- DT::renderDataTable(
select(filtered_table_df(), -Sum),
rownames= FALSE,
server = FALSE,
selection = "none",
options = list(pageLength = 25,
dom = "Blfrtip",
buttons = c("copy", "excel", "pdf")),
extensions = "Buttons"
)
# Tab: Kit Overview -------------------------------------------------------
## Pie chart metabolite overview
pie_table_df <- eventReactive(c(rv$go1, input$kit_overview[1]), {
temp_pie_df <- anno_row_df[anno_row_df$Class %in% input$class, ] %>%
droplevels() %>%
dplyr::select(c(Metabolite, Name, Class))
rownames(temp_pie_df) <- NULL
temp_pie_df})
pie_input_df <- reactive({
pie_df <- data.frame(Weight = 1, Class = pie_table_df()$Class) %>%
group_by(Class) %>%
dplyr::summarise(Weight = n()) %>%
arrange(desc(Class)) %>%
mutate(text_temp = cumsum(Weight),
text_y = cumsum(Weight) - Weight/2) %>%
arrange(Class) %>%
data.frame
pie_df})
output$pie_chart <- renderPlot({
ggplot(pie_input_df(), aes(x="", y=Weight, fill=Class)) +
geom_bar(width = 1, stat = "identity") +
coord_polar("y", start=0) +
scale_fill_manual(values = col_vector_classes) + theme_void() +
theme(axis.text.x=element_blank()) +
geom_label_repel(aes(label = Weight, y = text_y), size=4,
show.legend = F, nudge_x = 0.3)
})
## Metabolites in classes
output$metabolite_classes <- DT::renderDataTable(
pie_table_df(),
server = FALSE,
selection = "none",
options = list(dom = "Blfrtip",
buttons = c("copy", "excel", "pdf")),
extensions = "Buttons"
)
})