-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.R
1512 lines (1158 loc) · 74.9 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
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
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
###################################################################################### CHATDASHBOARD SETUP #####
################################### LOADING LIBRARIES ####
library(anytime)
library(crosstalk)
library(cyphr)
library(digest)
library(DT)
library(fontawesome)
library(ggplot2)
library(ggwordcloud)
library(keyring)
library(rsconnect)
library(shiny)
library(shinymanager)
library(shinythemes)
library(shinyjs)
library(shinyalert)
library(shinyTime)
library(shinyWidgets)
library(slickR)
library(utils)
library(waiter)
library(WhatsR)
################################### LANGUAGE SETTINGS ####
# language setting for shinymanager authentication page
# see: https://datastorm-open.github.io/shinymanager/reference/use_language.html
landing_page_language <- "en"
# Check: https://cdn.datatables.net/plug-ins/1.10.11/i18n/ for a
# list of different languages. Insert them by pasting the respective
# link according to the format below
datatable_language <- c('//cdn.datatables.net/plug-ins/1.10.11/i18n/English.json')
# import display text from csv file
ChatDashboard_DisplayText <- read.csv("./www/ChatDashboard_DisplayText.csv")
# Selecting column containing the text you want to display. English and German are preset options
display_text <- ChatDashboard_DisplayText$English
# For changing the display of individual text variables, you can simply edit the file
# ./www/ChatDashboard_DisplayText.csv, add an additional column, and select it above.
################################### SHINY SETTINGS ####
# Variable passed to WhatsR::parse_chat(). Automatically removes all chat messages from participants that did not post the EXACT consent_message into
# the chat. Setting this variable to NA will not remove any messages.
consent_message <- NA
# variable to control whether to use forwarding per url parameter or rely on pre-defined credentials for authentication
# TODO: If you are using url parameter forwarding, you need to adapt line 879 to extract the participant ID from your referral link.
# Default structure is: www.example-website.com/ChatDashboard?id=TestParticipant | Extracts: TestParticipant
use_forwarding <- FALSE
# Password to use for forwarding via url-parameter (only used if use_forwarding == TRUE)
# TODO: Set this as a character string in line 880
# saving donated files to server if TRUE, will not save any data if not TRUE
save_to_server <- TRUE
# setting upload file size limit
options(shiny.maxRequestSize = 50*1024^2)
# Set column names to be displayed to participants. This needs to be exactly 19 strings
# and does not determine whether these variables are displayed or not, but just how they are named
# in the display to participants
Colnames_ppt_display <- c("Timestamp",
"Sender",
"Sender_anonymized",
"Message",
"Message_simplified",
"Message_words",
"Links",
"Links_anonymized",
"Media",
"Media_anonymized",
"Locations",
"Locations_anonymized",
"Emoji",
"Emoji_description",
"Smilies",
"System_messages",
"Word_count",
"Time_order",
"Display_order")
# Set column names to be automatically excluded because they can contain PII (must occur in Colnames_ppt_display)
Colnames_exclude_pii <- c("Sender",
"Message",
"Message_simplified",
"Message_words",
"Links",
"Media",
"Locations",
"System_messages")
# Shiny Debugging Options (uncomment these to debug the app)
# options(shiny.error = browser)
# options(shiny.trace = TRUE)
################################### HANDLING SHINY MANAGER CREDENTILAS ####
# Switch for running local (FALSE) vs online (TRUE)
running_online = FALSE
if (running_online == TRUE) {.libPaths("YOUR-LIB-PATH-HERE")}
# TODO: Add library path of server here if running online
# loading credentials from external file
credentials <- readRDS("credentials.rds")
################################### MAKING FONT FOR EMOJI PLOTTING AVAILABLE ####
if (file.exists("~/.fonts/NotoColorEmoji.ttf")) {
system('fc-cache -f ~/.fonts')
} else {
dir.create('~/.fonts')
file.copy("www/NotoColorEmoji.ttf", "~/.fonts")
system('fc-cache -f ~/.fonts')
}
################################### DEFINING WAITING SCREENS ####
waiting_screen1 <- tagList(
spin_flower(),
h4(display_text[1])
)
waiting_screen2 <- tagList(
spin_flower(),
h4(display_text[2])
)
###################################################################################### SHINY SERVER UI #####
# Define UI for ChatDashboard application
ui <- fluidPage(theme = shinytheme("flatly"), window_title = "ChatDashboard",
##################################### UI SETUP ####
### Setting up shiny JS and shinyAlert
useShinyjs(),
# Background color
setBackgroundColor("#ECE5DD"),
useWaiter(),
# Styling and other colors
tags$style(type = 'text/css',
'.navbar { background-color: #25D366 ;}',
'.navbar-default .navbar-brand{color: white;}',
'.tab-panel{ background-color: red ; color: white}',
'.nav navbar-nav li.active:hover a, .nav navbar-nav li.active a {
background-color: orange ;
border-color: purple ;
}'
),
##################################### MAIN UI ####
# Logo and App name in navbar page
navbarPage(title = tags$img(height = 35,
width = 35,
src = "WhatsR_logo.png"),
id = "ChatDashboard",
##################################### Overview Page ####
tabPanel(display_text[3],
# whole page
fluidRow(
# Heading 1
column(tags$p(style = "text-align: justify;",
HTML(display_text[4])),
HTML("<br>"),
HTML(display_text[5]),
HTML("<br><br>"),
HTML(display_text[6]),
HTML("<br><br>"),
HTML(display_text[7]),
HTML("<br><br><br>"),
width = 6, offset = 3),
# Images
column(slickROutput("slickr",
width = "100%",
height = "100%"),
HTML("<br><br>"),
width = 6, offset = 3),
# Heading 2
column(tags$p(style = "text-align: justify;",
HTML(display_text[8]),
HTML(display_text[9]),
HTML("<br><br>")
),
width = 6, offset = 3),
# Heading 3
column(tags$p(style = "text-align: justify;",
HTML(display_text[10]),
HTML(display_text[11]),
HTML("<br><br>")
),
width = 6, offset = 3),
# Heading 4
column(tags$p(style = "text-align: justify;",
HTML(display_text[12]),
HTML(display_text[13]),
HTML("<br><br>")
),
width = 6, offset = 3),
# Consent button
column(12, align = "center",
actionButton("IntroCheck",
label = display_text[14],
class = "btn-warning",
style = "color: #040607; background-color: #25D366; border-color: #040607"),
HTML("<br><br><br><br><br><br>")
)
# End of fluidRow
)
# End of tabPanel
),
##################################### DATA UPLOAD PAGE ####
tabPanel(display_text[15],
# Sidebar
sidebarLayout(
sidebarPanel(h2(display_text[16],
align = "center"),
# Text for sidebar panel
helpText(display_text[18]),
helpText(display_text[19]),
# File selection field
fileInput(inputId = "file",
label = "",
accept = ".txt",
buttonLabel = display_text[20]
),
# Upload button
actionButton(inputId = "submit",
label = display_text[21],
class = "btn-warning",
style = "color: #040607; background-color: #25D366; border-color: #040607")
),
# Main panel
mainPanel(
column(
tags$p(
# Headline
HTML(display_text[22]),
# Text column
tags$p(style = "text-align: justify;",
HTML(display_text[23]),
HTML("<br><br>"),
HTML(display_text[24]),
HTML("<br><br>"),
HTML(display_text[25]),
HTML("<br><br>")
),
# Images and Headlines
HTML(display_text[26]),
tags$img(height = "auto",
width = "100%",
src = "DataExport_Guide_Android.png"),
HTML("<br><br>"),
HTML(display_text[27]),
tags$img(height = "auto",
width = "100%",
src = "WhatsApp_DataExport_iOS.png"),
HTML("<br><br>"),
# End paragraph
),
# end column
width = 10, offset = 1)
# end main panel
),
# End sidebar layout
)
# End tab panel
),
##################################### DATA EXPLORATION PAGE ####
tabPanel(display_text[28],
# Sidebar Panel
sidebarPanel(
# Info text
h2(display_text[29], align = "center"),
HTML(display_text[30]),
HTML("<br><br>"),
HTML(display_text[31]),
h3(display_text[32]),
helpText(display_text[33]),
# column selection
pickerInput("show_vars",
display_text[34],
choices = c(""),
selected = c(""),
label = display_text[35],
multiple = TRUE,
choicesOpt = list(style = c("color:black;font-weight: bold;",
"background:lightgrey;color:black",
"color:black;font-weight: bold;",
"background:lightgrey;color:black",
"background:lightgrey;color:black",
"background:lightgrey;color:black",
"background:lightgrey;color:black",
"color:black;font-weight: bold;",
"background:lightgrey;color:black",
"color:black;font-weight: bold;",
"background:lightgrey;color:black",
"color:black;font-weight: bold;",
"color:black;font-weight: bold;",
"color:black;font-weight: bold;",
"color:black;font-weight: bold;",
"background:lightgrey;color:black",
"color:black;font-weight: bold;",
"color:black;font-weight: bold;",
"color:black;font-weight: bold;"))),
# Row selection
h3(display_text[36]),
helpText(display_text[37]),
actionButton("excludeRows",display_text[38]),
actionButton("RestoreRows",display_text[39]),
# Data donation
h3(display_text[40]),
helpText(display_text[41]),
actionButton(inputId = "donation",
label = display_text[42],
class = "btn-warning",
style = "color: #040607; background-color: #25D366; border-color: #040607")
# End sidebar panel
),
# Main panel
mainPanel(
# Headline
h1(display_text[43],align = "center"),
HTML("<br>"),
# Dataframe
DTOutput("frame"),
# Download buttons
fluidRow(column(1,
align = "topright",
downloadButton("downloadSelection",
display_text[44])),
column(1,
align = "topleft",
downloadButton("downloadData",
display_text[45]),
offset = 9),),
# End main panel
)
# End tab panel
),
##################################### OVERALL RESULTS PAGE ####
tabPanel(display_text[46],
tabsetPanel(type = "tabs",
##################################### RESULTS: MESSAGES SUBPAGE ####
tabPanel(display_text[47],
# sidebar panel
sidebarPanel(h3(display_text[48], align = "center"),
tags$p(display_text[49]),
# Sender selection
h3(display_text[50]),
helpText(display_text[51]),
checkboxGroupButtons("Sender_input_msg",
"",
display_text[52]),
# Time selection
h3(display_text[53]),
helpText(display_text[54]),
dateRangeInput("date_range_messages",
label = display_text[55],
start = "2016-01-01",
end = NULL,
format = "dd-mm-yyyy",
startview = "year",
weekstart = 1,
language = landing_page_language,
autoclose = TRUE,
separator = display_text[56])
# End sidebar panel
),
# Main Panel
mainPanel(
# Plot 1
h1(display_text[57],align = "center"),
HTML(display_text[58]),
HTML("<br><br>"),
addSpinner(plotOutput("message1",
height = "600px"),
spin = "circle",
color = "#25D366"),
HTML("<br><br>"),
# Plot 2
h1(display_text[59],align = "center"),
HTML("<br><br>"),
addSpinner(plotOutput("tokensbwah1",
height = "600px"),
spin = "circle",
color = "#25D366"),
HTML("<br><br>"),
# plot 3
addSpinner(plotOutput("tokensbwah2",
height = "600px"),
spin = "circle",
color = "#25D366")
# End main panel
),
# end tab panel
width = 6, offset = 5),
##################################### RESULTS: LINKS SUBPAGE ####
tabPanel(display_text[60],
# sidebar panel
sidebarPanel(h3(display_text[48], align = "center"),
tags$p(display_text[61]),
# sender selection
h3(display_text[50]),
helpText(display_text[51]),
checkboxGroupButtons("Sender_input_links",
"",
display_text[62]),
# timespan selection
h3(display_text[55]),
helpText(display_text[54]),
dateRangeInput("date_range_links",
label = display_text[55],
start = "2016-01-01",
end = NULL,
format = "dd-mm-yyyy",
startview = "year",
weekstart = 1,
language = landing_page_language,
autoclose = TRUE,
separator = display_text[56]),
# Link Minimum selection
h3(display_text[63]),
helpText(display_text[64]),
sliderInput("LinkMinimum",
"",
min = 1,
max = 100,
value = 5)
# End sidebar panel
),
# Main Panel
mainPanel(
# Plot 1
h3(display_text[65], align = "center"),
HTML(display_text[58]),
addSpinner(plotOutput("links4",
height = "600px"),
spin = "circle",
color = "#25D366"),
HTML("<br><br>"),
# plot 2
addSpinner(plotOutput("links2",
height = "600px"),
spin = "circle",
color = "#25D366"),
HTML("<br><br>"),
# plot 3
addSpinner(plotOutput("links1",
height = "600px"),
spin = "circle",
color = "#25D366"),
HTML("<br><br>"),
),
width = 6, offset = 5),
##################################### RESULTS: SMILIES SUBPAGE ####
tabPanel(display_text[66],
# sidebar panel
sidebarPanel(h3(display_text[48], align = "center"),
tags$p(display_text[67]),
# sender selection
h3(display_text[50]),
helpText(display_text[51]),
checkboxGroupButtons("Sender_input_smilies",
"",
display_text[52]),
# time range selection
h3(display_text[53]),
helpText(display_text[54]),
dateRangeInput("date_range_smilies",
label = display_text[55],
start = "2016-01-01",
end = NULL,
format = "dd-mm-yyyy",
startview = "year",
weekstart = 1,
language = landing_page_language,
autoclose = TRUE,
separator = display_text[56]),
# smilie minimum selection
h3(display_text[63]),
helpText(display_text[68]),
sliderInput("SmilieMinimum",
"", min = 1,
max = 100,
value = 5)
),
# Main Panel
mainPanel(
# Plot 1
h3(display_text[69], align = "center"),
HTML(display_text[58]),
addSpinner(plotOutput("smilies4",
height = "600px"),
spin = "circle",
color = "#25D366"),
HTML("<br><br>"),
# Plot 2
addSpinner(plotOutput("smilies2",
height = "600px"),
spin = "circle",
color = "#25D366"),
HTML("<br><br>"),
# Plot 3
addSpinner(plotOutput("smilies1",
height = "600px"),
spin = "circle",
color = "#25D366"),
HTML("<br><br>"),
# end main panel
),
# end tabpanel
width = 6, offset = 5),
##################################### RESULTS: EMOJI SUBPAGE ####
tabPanel(display_text[70],
# sidebar panel
sidebarPanel(h3(display_text[48], align = "center"),
tags$p(display_text[71]),
# sender selection
h3(display_text[50]),
helpText(display_text[51]),
checkboxGroupButtons("Sender_input_emoji",
"",
display_text[62]),
# timeframe selection
h3(display_text[53]),
helpText(display_text[54]),
dateRangeInput("date_range_emoji",
label = display_text[55],
start = "2016-01-01",
end = NULL,
format = "dd-mm-yyyy",
startview = "year",
weekstart = 1,
language = landing_page_language,
autoclose = TRUE,
separator = display_text[56]),
# minimum emoji selection
h3(display_text[63]),
helpText(display_text[72]),
sliderInput("EmojiMinimum",
"",
min = 1,
max = 100,
value = 50)
# end sidebar panel
),
# Main Panel
mainPanel(
# Plot 1
h3(display_text[73],
align = "center"),
HTML(display_text[58]),
addSpinner(plotOutput("emoji4",
height = "600px"),
spin = "circle",
color = "#25D366"),
HTML("<br><br>"),
# Plot 2
addSpinner(plotOutput("emoji2",
height = "600px"),
spin = "circle",
color = "#25D366"),
HTML("<br><br>"),
# Plot 3
addSpinner(plotOutput("emoji1",
height = "600px"),
spin = "circle",
color = "#25D366"),
HTML("<br><br>"),
# end main panel
),
# end tabpanel
width = 6, offset = 5),
##################################### RESULTS: REPLYTIMES SUBPAGE ####
tabPanel(display_text[74],
# sidebar panel
sidebarPanel(h3(display_text[48], align = "center"),
tags$p(display_text[75]),
# sender selection
h3(display_text[50]),
helpText(display_text[51]),
checkboxGroupButtons("Sender_input_replies",
"",
display_text[52]),
# timeframe selection
h3(display_text[53]),
helpText(display_text[54]),
dateRangeInput("date_range_replies",
label = display_text[55],
start = "2016-01-01",
end = NULL,
format = "dd-mm-yyyy",
startview = "year",
weekstart = 1,
language = landing_page_language,
autoclose = TRUE,
separator = display_text[56])
),
# Main Panel
mainPanel(
# Plot 1
h3(display_text[74], align = "center"),
HTML(display_text[58]),
addSpinner(plotOutput("replytime1",
height = "600px"),
spin = "circle",
color = "#25D366"),
HTML("<br><br>"),
# Plot 2
addSpinner(plotOutput("replytime2",
height = "600px"),
spin = "circle",
color = "#25D366")
# End main panel
),
# end tab panel
width = 6, offset = 5)
# End tabset panel
)
# End tab Panel
),
##################################### RESULTS: IMPRESSUM PAGE ####
tabPanel(display_text[76],
column(tags$p(
HTML(display_text[77])),
width = 6, offset = 5))
# End navbarpage
)
# End ui
)
###################################################################################### SECURING APP WITH SHINYMANAGER #####
# Wrapping UI with secure_app for password protection
ui <- secure_app(ui,language = landing_page_language)
###################################################################################### SHINY SERVER LOGIC #####
# Defining server logic
server <- function(input, output, session) {
################################### BASIC SETUP ####
#### Creating Slideshow with SlickR
output$slickr <- renderSlickR({
imgs <- list.files("./www/Slideshow", pattern = ".png", full.names = TRUE)
slickR(imgs)
})
# creating empty reactive value for storing uploaded data
rv <- reactiveValues(data = NULL)
################################### STYLING, BUTTONS, HIDE/UNHIDE ELEMENTS ####
# hiding tabs that should only be shown conditionally
hideTab("ChatDashboard",display_text[28],session = session)
hideTab("ChatDashboard",display_text[46],session = session)
hideTab("ChatDashboard",display_text[15],session = session)
# unhide tabs when the button on first page is clicked
observeEvent(input$IntroCheck, {
# rerouting to data upload page and hiding Overview page
showTab("ChatDashboard",display_text[15],session = session)
hideTab("ChatDashboard",display_text[3],session = session)
updateNavbarPage(session, "ChatDashboard",display_text[15])
})
# Submitting uploaded data
observeEvent(input$submit, {
# rerouting to 'explore data' tab and hiding upload tab
showTab("ChatDashboard",display_text[28],session = session)
hideTab("ChatDashboard",display_text[15],session = session)
updateNavbarPage(session, "ChatDashboard",display_text[28])
})
#### Hiding/unhiding buttons
# hiding the download buttons if no file has been uploaded
observe({
shinyjs::hide("submit")
if (!is.null(input$file))
shinyjs::show("submit")
})
observe({
shinyjs::hide("downloadData")
if (is.data.frame(rv$data))
shinyjs::show("downloadData")
})
observe({
shinyjs::hide("downloadSelection")
if (is.data.frame(rv$data))
shinyjs::show("downloadSelection")
})
observe({
shinyjs::hide("excludeRows")
if (is.data.frame(rv$data))
shinyjs::show("excludeRows")
})
observe({
shinyjs::hide("RestoreRows")
if (is.data.frame(rv$data))
shinyjs::show("RestoreRows")
})
################################### SHINYMANAGER/PASSWORD MANAGMENT ####
# authentication either with url parameter forwarding or with preset credentials
if (use_forwarding == TRUE) {
# using manually set password for forwarding
res_auth <- secure_server(
check_credentials = check_credentials(rbind.data.frame(credentials,
# This automatically adds the string at the end of the referral link as a username
# to the credentials file, ensuring that participant IDs generated by your
# survey tool can be used as valid usernames. This enables data linking.
# TODO: Might need to be adapted to the structure of the referral link.
c(unlist(strsplit(strsplit(session$clientData$url_search,"&")[[1]][1],"="))[2],
"password", # TODO: Set your forwarding password here!
"2019-04-15",
NA,
FALSE,
"Participant Account"
)
))
)
} else {
# using user/password combinations from credentials.rds file
res_auth <- secure_server(check_credentials = check_credentials(credentials))
}
################################### DATA UPLOAD & PARSING ####
# trigger only when data is submitted
observeEvent(input$submit, {
# require inputs
req(input$file)
# show waiting animation
waiter_show(html = waiting_screen1, color = "#25D366")
# parsing upload
rv$data <- parse_chat(path = input$file$datapath,
anonymize = "add",
consent = consent_message)
# saving old column names
rv$FunctionColnames <- colnames(rv$data)
# creating new column names for better display to participants
colnames(rv$data) <- Colnames_ppt_display
# making an internal copy for column and row selection and
# better data display
rv$copy <- rv$data
# Changing formatting of columns with multiple values per cell
# for nicer display in datatable
rv$copy[,6] <- as.character(lapply(rv$copy[,6],paste,collapse = ","))
rv$copy[,7] <- as.character(lapply(rv$copy[,7],paste,collapse = ","))
rv$copy[,8] <- as.character(lapply(rv$copy[,8],paste,collapse = ","))
rv$copy[,9] <- as.character(lapply(rv$copy[,9],paste,collapse = ","))
rv$copy[,10] <- as.character(lapply(rv$copy[,10],paste,collapse = ","))
rv$copy[,13] <- as.character(lapply(rv$copy[,13],paste,collapse = ","))
rv$copy[,14] <- as.character(lapply(rv$copy[,14],paste,collapse = ","))
rv$copy[,15] <- as.character(lapply(rv$copy[,15],paste,collapse = ","))
# replacing textual NAs with proper NAs
rv$copy[,6][rv$copy[,6] == "NA"] <- NA
rv$copy[,7][rv$copy[,7] == "NA"] <- NA
rv$copy[,8][rv$copy[,8] == "NA"] <- NA
rv$copy[,9][rv$copy[,9] == "NA"] <- NA
rv$copy[,10][rv$copy[,10] == "NA"] <- NA
rv$copy[,13][rv$copy[,13] == "NA"] <- NA
rv$copy[,14][rv$copy[,14] == "NA"] <- NA
rv$copy[,15][rv$copy[,15] == "NA"] <- NA
# hide waiting animation
waiter_hide()
})
################################### RENDERING DATAFRAME
# rendering copy of the dataframe
output$frame <- renderDT({
# require necessary inputs
req(input$show_vars,rv$copy)
# only displaying data if at least two columns are selected, do nothing if less are selected
if (length(input$show_vars) >= 2) {
# coloring non-donateable columns grey after checking if they're present
color_identifier <- colnames(rv$copy[as.numeric(rownames(rv$copy)),c(input$show_vars)])[colnames(rv$copy[as.numeric(rownames(rv$copy)),c(input$show_vars)]) %in% Colnames_exclude_pii]
# inner if
if (length(color_identifier) > 0) {datatable(rv$copy[,c(input$show_vars)],
options = list(scrollY = "750px",
scrollX = TRUE,
ordering = F,
language = list(url = datatable_language)
,columnDefs = list(list(
targets = "_all",
render = JS(
"function(data, type, row, meta) {",
"return type === 'display' && data != null && data.length > 35 ?",
"'<span title=\"' + data + '\">' + data.substr(0, 50) + '...</span>' : data;",
"}")))
# end inner if
)) %>% formatStyle(color_identifier,backgroundColor = "lightgrey")}
# inner else
else{datatable(rv$copy[,c(input$show_vars)], options = list(scrollY = "750px",
scrollX = TRUE,
ordering = F,
language = list(url = datatable_language)
,columnDefs = list(list(
targets = "_all",
render = JS(
"function(data, type, row, meta) {",
"return type === 'display' && data != null && data.length > 35 ?",
"'<span title=\"' + data + '\">' + data.substr(0, 50) + '...</span>' : data;",
"}")))
# End inner else
))}
# outer else
} else{