forked from jankovicd/STEER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
1759 lines (1166 loc) · 65.2 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
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
library(rdrop2)
source("manual_inputs.R", local = TRUE)
source("functions.R", local = TRUE)
source("elicitation_questions_ui.R", local = TRUE)
source("about_you.R", local = TRUE)
function (input, output, session) {
##### create reactive values #####
# reactive values where experts' responses are stored
# ($test used in practice question in "instructions" tab)
elici_minis <- reactiveValues(test = 9) # lower limit of expert's plausible range
elici_maxis <- reactiveValues(test = 17) # upper limit of expert's plausible range
if(elicitation_method == "chips and bins"){
chips_width <- reactiveValues(test = 1) # bin width
chips_lower <- reactiveValues(test = 8) # lower limit of the plot
chips_upper <- reactiveValues(test = 18) # upper limit of the plot
chips_nbins <- reactiveValues(test = 10) # total number of bins
chips_nchip <- reactiveValues(test = 20) # total number of chips
chips_nhigh <- reactiveValues(test = 20) # height of plot
chips_lbins <- reactiveValues(test = 8:17) # lower limit of each bin
chips_rbins <- reactiveValues(test = 9:18) # upper limit of each bin
chips_value <- reactiveValues(test = 9:18) # bins (equal to rbins)
chips_chips <- reactiveValues(test = rep(0,10)) # number of chips in each bin
show_plot <- reactiveValues(test=0) # indicator (>0) that experts have entered (or updated) their plausible range for chips and bins
enter_plot <- reactiveValues(test=0) #indicator (>0) that experts have used all chips
} else if (elicitation_method == "quartiles") {
elici_q1 <- reactiveValues(test = 11) # expert's lower quartile
elici_q2 <- reactiveValues(test = 12) # expert's median
elici_q3 <- reactiveValues(test = 14) #expert's upper quartile
enter_min_max <- reactiveValues(test=0) # indicator (>0) that experts have entered (or updated) their plausible range for quertiles/tertiles
enter_quarts <- reactiveValues(test=0) # indicator (>0) that experts have entered (or updated) their quartiles
} else if (elicitation_method == "tertiles") {
elici_t1 <- reactiveValues(test = 12) # expert's lower tertile
elici_t2 <- reactiveValues(test = 14) # expert's upper tertile
enter_min_max <- reactiveValues(test=0) # indicator (>0) that experts have entered (or updated) their plausible range for quertiles/tertiles
enter_terts <- reactiveValues(test=0) # indicator (>0) that experts have entered (or updated) their tertiles
}
comments <- reactiveValues(test="") # expert's comments about elicitation questions
buttons <- reactiveValues(expert_id = 0, # expert's unique code provided by the investigator that distinguished their saved answers from others'
enter_unique_id = 0, # indicator (>0) that the expert has entered their unique identifier
next_home = 0, # current page on the home tab
end_home = 0, # indicator (>0) that the expert is on the last page of the home tab
next_que_0 = 0, # indicator (>0) that training is complete, switch to next tab
start_que = 0, # indicator (>0) that the expert has read background information
que_no = 1, # the next question the expert needs to answer
enter_previous_responses = 0,
radio_previous_responses = 0,
get_previous_responses = 0)
save <- reactiveValues(about_you_all = 0, # object for saving "about you" questions
about_you_colnames = "expert_id", # column names for "about_you" questions
all_answers = 0,
all_answers_colnames = 0)
if (dummy_app) {
buttons$expert_id <- 1111
buttons$enter_unique_id <- 1
save$about_you_all <- 1111
}
for (i in eli_que_names){
# create reactive values where experts' responses are stored
elici_minis[[i]] <- integer(0)
elici_maxis[[i]] <- integer(0)
comments[[i]] <- ""
if(elicitation_method == "chips and bins"){
chips_width[[i]] <- 0
chips_lower[[i]] <- 0
chips_upper[[i]] <- 0
chips_nbins[[i]] <- 0
chips_nchip[[i]] <- 0
chips_nhigh[[i]] <- 0
chips_lbins[[i]] <- 0
chips_rbins[[i]] <- 0
chips_value[[i]] <- 0
chips_chips[[i]] <- 0
show_plot[[i]] <- 0
enter_plot[[i]] <- 0
} else if (elicitation_method == "quartiles"){
elici_q1[[i]] <- integer(0)
elici_q2[[i]] <- integer(0)
elici_q3[[i]] <- integer(0)
enter_min_max[[i]] <- 0
enter_quarts[[i]] <-0
buttons[[paste0("conditions_",i)]] <- 0
} else if (elicitation_method == "tertiles"){
elici_t1[[i]] <- integer(0)
elici_t2[[i]] <- integer(0)
enter_min_max[[i]] <- 0
enter_terts[[i]] <-0
buttons[[paste0("conditions_",i)]] <- 0
}
save[[i]] <- 0 # saves elicitation answers
save[[paste0(i,"_colnames")]] <- 0 # column names for elicitation answers
}
##### button clicks #####
observeEvent(input$enter_previous_responses,{
buttons$enter_previous_responses <- 1
buttons$radio_previous_responses <- input$radio_previous_responses
})
observeEvent(input$get_previous_responses, {
file1 <- input[["load_past_answers"]]
ext <- tools::file_ext(file1$datapath)
req(file1)
validate(need(ext == "csv", "Please upload a csv file"))
previous_responses <- read.csv(file1$datapath, header = TRUE)[-1]
buttons$expert_id <- previous_responses["expert_id"]
buttons$enter_unique_id <- 1
save[["all_answers"]] <- previous_responses
save[["all_answers_colnames"]] <- colnames(previous_responses)
if(include_about_you){
about_you <- previous_responses[grep("about_you",colnames(previous_responses))]
if(length(about_you)>0){
save[["about_you_all"]] <- c(buttons$expert_id, as.numeric(previous_responses[grep("about_you_",colnames(previous_responses))]))
save[["about_you_colnames"]] <- c("expert_id", colnames(previous_responses)[grep("about_you_",colnames(previous_responses))])
}
}
# check answers relating to elicitation
temp1 <- colnames(previous_responses)[grep("_min",colnames(previous_responses))]
if(length(temp1)>0){
# get the list of elicitation questions the experts had answered before
answered_questions <- as.numeric(gsub(".*?([0-9]+).*", "\\1", temp1))
for (i in answered_questions) {
# reload experts previous answers into reactive values
que_name <- eli_que_names[i]
elici_minis[[que_name]] <- as.numeric(previous_responses[paste0(que_name,"_min")])
elici_maxis[[que_name]] <- as.numeric(previous_responses[paste0(que_name,"_max")])
if(paste0(que_name,"_comment")%in%colnames(previous_responses)){
comments[[que_name]] <- as.character(previous_responses[paste0(que_name,"_comment")])
}
if(elicitation_method == "chips and bins"){
chips_width[[que_name]] <- f_width(elici_minis[[que_name]], elici_maxis[[que_name]], bins)
chips_lower[[que_name]] <- f_lower(elici_minis[[que_name]], chips_width[[que_name]], quant_limit_lower[i])
chips_upper[[que_name]] <- f_upper(elici_maxis[[que_name]], chips_width[[que_name]], quant_limit_upper[i])
chips_nbins[[que_name]] <- f_nbins(chips_lower[[que_name]], chips_upper[[que_name]], chips_width[[que_name]])
chips_nchip[[que_name]] <- 2 * chips_nbins[[que_name]]
chips_nhigh[[que_name]] <- 2 * chips_nbins[[que_name]]
chips_lbins[[que_name]] <- f_lbins(chips_lower[[que_name]], chips_upper[[que_name]], chips_width[[que_name]])
chips_rbins[[que_name]] <- f_rbins(chips_lower[[que_name]], chips_upper[[que_name]], chips_width[[que_name]])
chips_value[[que_name]] <- chips_rbins[[que_name]]
chips_chips[[que_name]] <- unlist(previous_responses[grep(paste0(que_name,"_chip"),colnames(previous_responses))])
show_plot[[que_name]] <- 1
enter_plot[[que_name]] <- 1
} else if (elicitation_method == "quartiles"){
elici_q1[[que_name]] <- unlist(previous_responses[paste0(que_name,"_lower_quartile")])
elici_q2[[que_name]] <- unlist(previous_responses[paste0(que_name,"_median")])
elici_q3[[que_name]] <- unlist(previous_responses[paste0(que_name,"_upper_quartile")])
enter_min_max[[que_name]] <- 1
enter_quarts[[que_name]] <- 1
buttons[[paste0("conditions_",i)]] <- 1
} else {
elici_t1[[que_name]] <- unlist(previous_responses[paste0(que_name,"_lower_tertile")])
elici_t2[[que_name]] <- unlist(previous_responses[paste0(que_name,"_upper_tertile")])
enter_min_max[[que_name]] <- 1
enter_terts[[que_name]] <- 1
buttons[[paste0("conditions_",i)]] <- 1
}
}
buttons$next_home <- last_home_page
buttons$end_home <- 1
buttons$next_que <- 1
buttons$start_que <- 1
buttons$que_no <- answered_questions[length(answered_questions)] + 1
updateTabsetPanel(session, "top_tabs", selected = "Questions")
} else {
temp2 <- colnames(previous_responses)[grep("about_you",colnames(previous_responses))]
if (length(temp2)>0){
# if the expert has answered "about_you" questions, skip to "Instructions" tab
buttons$next_home <- last_home_page
buttons$end_home <- 1
updateTabsetPanel(session, "top_tabs",
selected = "Instructions"
)
}
}
})
observeEvent(input$enter_unique_id,{
if ("expert_id"%in%names(input)) {
# if an expert has entered their ID, checks whether they had saved any
# answers before, and if yes, uploads them
if(input$expert_id%in%all_expert_ids) {
#check that the unique id is one included in all_expert_ids
buttons$expert_id <- input$expert_id
save$about_you_all <- buttons$expert_id
buttons$enter_unique_id <- 1
if(save_method == "dropbox"){
# load previous answers
previous_responses <- f_load_answers(buttons$expert_id)
if(!is.na(previous_responses[1])){
# if there were any saved answers, check those relating to elicitation
temp1 <- colnames(previous_responses)[grep("_min",colnames(previous_responses))]
if(length(temp1)>0){
# get the list of elicitation questions the experts had answered before
answered_questions <- as.numeric(gsub(".*?([0-9]+).*", "\\1", temp1))
for (i in answered_questions) {
# reload experts previous answers into reactive values
que_name <- eli_que_names[i]
elici_minis[[que_name]] <- as.numeric(previous_responses[paste0(que_name,"_min")])
elici_maxis[[que_name]] <- as.numeric(previous_responses[paste0(que_name,"_max")])
if(paste0(que_name,"_comment")%in%colnames(previous_responses)){
comments[[que_name]] <- as.character(previous_responses[paste0(que_name,"_comment")])
}
if(elicitation_method == "chips and bins"){
chips_width[[que_name]] <- f_width(elici_minis[[que_name]], elici_maxis[[que_name]], bins)
chips_lower[[que_name]] <- f_lower(elici_minis[[que_name]], chips_width[[que_name]], quant_limit_lower[i])
chips_upper[[que_name]] <- f_upper(elici_maxis[[que_name]], chips_width[[que_name]], quant_limit_upper[i])
chips_nbins[[que_name]] <- f_nbins(chips_lower[[que_name]], chips_upper[[que_name]], chips_width[[que_name]])
chips_nchip[[que_name]] <- 2 * chips_nbins[[que_name]]
chips_nhigh[[que_name]] <- 2 * chips_nbins[[que_name]]
chips_lbins[[que_name]] <- f_lbins(chips_lower[[que_name]], chips_upper[[que_name]], chips_width[[que_name]])
chips_rbins[[que_name]] <- f_rbins(chips_lower[[que_name]], chips_upper[[que_name]], chips_width[[que_name]])
chips_value[[que_name]] <- chips_rbins[[que_name]]
chips_chips[[que_name]] <- unlist(previous_responses[grep(paste0(que_name,"_chip"),colnames(previous_responses))])
show_plot[[que_name]] <- 1
enter_plot[[que_name]] <- 1
} else if (elicitation_method == "quartiles"){
elici_q1[[que_name]] <- unlist(previous_responses[paste0(que_name,"_lower_quartile")])
elici_q2[[que_name]] <- unlist(previous_responses[paste0(que_name,"_median")])
elici_q3[[que_name]] <- unlist(previous_responses[paste0(que_name,"_upper_quartile")])
enter_min_max[[que_name]] <- 1
enter_quarts[[que_name]] <- 1
} else {
elici_t1[[que_name]] <- unlist(previous_responses[paste0(que_name,"_lower_tertile")])
elici_t2[[que_name]] <- unlist(previous_responses[paste0(que_name,"_upper_tertile")])
enter_min_max[[que_name]] <- 1
enter_terts[[que_name]] <- 1
}
}
buttons$next_home <- last_home_page
buttons$end_home <- 1
buttons$next_que <- 1
buttons$start_que <- 1
buttons$que_no <- answered_questions[length(answered_questions)] + 1
updateTabsetPanel(session, "top_tabs", selected = "Questions")
} else {
temp2 <- colnames(previous_responses)[grep("about_you",colnames(previous_responses))]
if (length(temp2)>0){
# if the expert has answered "about_you" questions, skip to "Instructions" tab
buttons$next_home <- last_home_page
buttons$end_home <- 1
updateTabsetPanel(session, "top_tabs",
selected = "Instructions"
)
}
}
}
}
} else {
showModal(modalDialog (uiOutput ("no_unique_id"), size="l"))
}
} else {
showModal(modalDialog (uiOutput ("no_unique_id"), size="l"))
}
})
if(save_method == "local"){
output[["download_about_you"]] <-
downloadHandler(
filename = paste0(buttons$expert_id,"_download_all.csv"),
content = function(con) {
temp <- buttons$next_home; buttons$next_home + 1
buttons$end_home <- 1
updateTabsetPanel(session, "top_tabs", selected = "Instructions")
for (i in 1:n_about_you){
# loop for saving all questions about experts
about_you_que <- paste0("about_you_",i)
if (about_you_que%in%names(input)){
if(!is.null(input[[about_you_que]])){
save_about_you_que <- input[[about_you_que]]
save_about_you_colnames <- rep(paste0("about_you_", i), length(save_about_you_que))
} else {
save_about_you_que <- NA
save_about_you_colnames <- paste0("about_you_", i)
}
} else {
save_about_you_que <- NA
save_about_you_colnames <- paste0("about_you_",i)
}
save[["about_you_all"]] <- c(save[["about_you_all"]], save_about_you_que)
save[["about_you_colnames"]] <- c(save[["about_you_colnames"]], save_about_you_colnames)
} #close for loop for "about you" questions
save[["all_answers"]] <- save[["about_you_all"]]
save[["all_answers_colnames"]] <- save[["about_you_colnames"]]
data <- t(save[["all_answers"]])
colnames(data) <- save[["all_answers_colnames"]]
# data <- t(save[["about_you_all"]])
# colnames(data) <- save[["about_you_colnames"]]
write.csv(data, con)
}
)
}
observeEvent(input$next_home,{
# allows the user to move through different pages of the Home screen
# (home page, consent form and questions about experts, if relevant)
if (!include_about_you){
# if not asking questions about experts, move onto next page on the Home tab
temp <- buttons$next_home; buttons$next_home <- temp + 1
if(buttons$next_home == last_home_page){
# if expert is on the last page of the Home tab, move to "Instructions tab"
buttons$end_home <- 1
updateTabsetPanel(session, "top_tabs",
selected = "Instructions"
)
}
} else if (buttons$next_home < (last_home_page-1)){
temp <- buttons$next_home; buttons$next_home <- temp + 1
} else {
if(save_method == "dropbox"){
for (i in 1:n_about_you){
# loop for saving all questions about experts
about_you_que <- paste0("about_you_",i)
if (about_you_que%in%names(input)){
if(!is.null(input[[about_you_que]])){
save_about_you_que <- input[[about_you_que]]
save_about_you_colnames <- rep(paste0("about_you_", i), length(save_about_you_que))
} else {
save_about_you_que <- NA
save_about_you_colnames <- paste0("about_you_", i)
}
} else {
save_about_you_que <- NA
save_about_you_colnames <- paste0("about_you_",i)
}
save[["about_you_all"]] <- c(save[["about_you_all"]],save_about_you_que)
save[["about_you_colnames"]] <- c(save[["about_you_colnames"]],save_about_you_colnames)
} #close for loop for "about you" questions
f_save_answers(save[["about_you_all"]], save[["about_you_colnames"]], paste0(buttons$expert_id,"_about_you.csv"))
}
temp <- buttons$next_home; buttons$next_home + 1
buttons$end_home <- 1
updateTabsetPanel(session, "top_tabs",
selected = "Instructions"
)
} #close actions relating to "about you" questions
})
# when using Chips and Bins, and an expert enters or updates their plausible range
lapply(X = 1:tot_eli_ques, FUN = function(i){
observeEvent(input[[paste0("show_plot_",i)]],{
que_name <- eli_que_names[i]
# save inputs as reactive values
elici_minis[[que_name]] <- input[[paste0("min",i)]]
elici_maxis[[que_name]] <- input[[paste0("max",i)]]
#check whether plausible range is within parameter limits and elici_minis < elici_maxis
condition <- f_cond_min_max(elici_minis[[que_name]], elici_maxis[[que_name]], quant_limit_lower[i], quant_limit_upper[i])
if(condition==1){
show_plot[[que_name]] <- 1 # show plot
enter_plot[[que_name]] <- 0 # do not show feedback on expert's plot
# update plot parameters
chips_width[[que_name]] <- f_width(elici_minis[[que_name]], elici_maxis[[que_name]], bins)
chips_lower[[que_name]] <- f_lower(elici_minis[[que_name]], chips_width[[que_name]], quant_limit_lower[i])
chips_upper[[que_name]] <- f_upper(elici_maxis[[que_name]], chips_width[[que_name]], quant_limit_upper[i])
chips_nbins[[que_name]] <- f_nbins(chips_lower[[que_name]], chips_upper[[que_name]], chips_width[[que_name]])
chips_nchip[[que_name]] <- 2 * chips_nbins[[que_name]]
chips_nhigh[[que_name]] <- 2 * chips_nbins[[que_name]]
chips_lbins[[que_name]] <- f_lbins(chips_lower[[que_name]], chips_upper[[que_name]], chips_width[[que_name]])
chips_rbins[[que_name]] <- f_rbins(chips_lower[[que_name]], chips_upper[[que_name]], chips_width[[que_name]])
chips_value[[que_name]] <- chips_rbins[[que_name]]
chips_chips[[que_name]] <- rep(0,chips_nbins[[que_name]])
} else {
# if condition == 0, who error message
showModal(modalDialog (uiOutput (paste0("no_plot_",i)), size="l"))
}
})
}
)
# when using Chips and Bins, and an expert enters or updates their plot
lapply(X = 1:tot_eli_ques, FUN = function(i){
observeEvent(input[[paste0("enter_plot_",i)]],{
que_name <- eli_que_names[i]
if(round(chips_nchip[[que_name]]-sum(chips_chips[[que_name]]),digits=0) > 0 ){
# error mesage if not all chips are used
showModal(modalDialog (uiOutput ("no_chips"), size="l"))
} else {
enter_plot[[que_name]] <- 1
}
})
})
#same as above, for the test plot
observeEvent(input[["enter_plot_0"]],{
if(sum(chips_chips[["test"]]) < chips_nchip[["test"]]){
showModal(modalDialog (uiOutput ("no_chips"), size="l"))
} else {
enter_plot[["test"]] <- 1
}
})
# when using quartiles or tertiles and an expert enters their plausible range
lapply(X = 1:tot_eli_ques, FUN = function(i){
observeEvent(input[[paste0("enter_min_max_",i)]],{
que_name <- eli_que_names[i]
# save inputs as reactive values
elici_minis[[que_name]] <- input[[paste0("min",i)]]
elici_maxis[[que_name]] <- input[[paste0("max",i)]]
#check whether the plausible range is within parameter limits and elici_minis < elici_maxis
condition <- f_cond_min_max(elici_minis[[que_name]], elici_maxis[[que_name]], quant_limit_lower[i], quant_limit_upper[i])
if(condition==1){
enter_min_max[[que_name]] <- 1
} else {
#show error message if condition = 0
showModal(modalDialog (uiOutput (paste0("no_plot_",i)), size="l"))
}
})
})
# when using quartiles and an expert enters their quartiles
lapply(X = 1:tot_eli_ques, FUN = function(i){
observeEvent(input[[paste0("enter_quarts_",i)]],{
que_name <- eli_que_names[i]
# save most recent minimum and maximum again, in case they were updated
elici_minis[[que_name]] <- input[[paste0("min",i)]]
elici_maxis[[que_name]] <- input[[paste0("max",i)]]
# save inputs as reactive values
elici_q1[[que_name]] <- input[[paste0("quartile1_",i)]]
elici_q2[[que_name]] <- input[[paste0("quartile2_",i)]]
elici_q3[[que_name]] <- input[[paste0("quartile3_",i)]]
#check whether the plausible range is within parameter limits and elici_minis < elici_maxis
condition1 <- f_cond_min_max(elici_minis[[que_name]], elici_maxis[[que_name]], quant_limit_lower[i], quant_limit_upper[i])
# check whether quartiles are within plausible range and quartiles are in logical order
condition2 <- f_cond_quartiles(elici_minis[[que_name]], elici_maxis[[que_name]], elici_q1[[que_name]], elici_q2[[que_name]], elici_q3[[que_name]])
if(condition1 == 1 & condition2 == 1){
enter_quarts[[que_name]] <- 1
if(save_method == "local") { buttons[[paste0("conditions_",i)]] <- 1 }
} else {
showModal(modalDialog (uiOutput (paste0("no_quantiles_",i)), size="l"))
}
})
})
#same as above, for the test question
observeEvent(input[["enter_quarts_0"]],{
# save inputs as reactive values
elici_q1[["test"]] <- input[["quartile1_0"]]
elici_q2[["test"]] <- input[["quartile2_0"]]
elici_q3[["test"]] <- input[["quartile3_0"]]
#check whether the plausible range is within parameter limits and elici_minis < elici_maxis
condition1 <- f_cond_min_max(elici_minis[["test"]], elici_maxis[["test"]], 0, NA)
# check whether quartiles are within plausible range and quartiles are in logical order
condition2 <- f_cond_quartiles(elici_minis[["test"]], elici_maxis[["test"]], elici_q1[["test"]], elici_q2[["test"]], elici_q3[["test"]])
if(condition1 == 1 & condition2 == 1){
enter_quarts[["test"]] <- 1
} else {
showModal(modalDialog (uiOutput ("no_quantiles_0"), size="l"))
}
})
# when using tertiles and an expert enters their tertiles
lapply(X = 1:tot_eli_ques, FUN = function(i){
observeEvent(input[[paste0("enter_terts_",i)]],{
que_name <- eli_que_names[i]
# save inputs as reactive values
elici_minis[[que_name]] <- input[[paste0("min",i)]]
elici_maxis[[que_name]] <- input[[paste0("max",i)]]
# save inputs as reactive values
elici_t1[[que_name]] <- input[[paste0("tertile1_",i)]]
elici_t2[[que_name]] <- input[[paste0("tertile2_",i)]]
#check whether the plausible range is within parameter limits and elici_minis < elici_maxis
condition1 <- f_cond_min_max(elici_minis[[que_name]], elici_maxis[[que_name]], quant_limit_lower[i], quant_limit_upper[i])
#check whether quartiles are within plausible range and tertiles are in logical order
condition2 <- f_cond_tertiles(elici_minis[[que_name]], elici_maxis[[que_name]], elici_t1[[que_name]], elici_t2[[que_name]])
if(condition1 == 1 & condition2 == 1){
enter_terts[[que_name]] <- 1
if(save_method == "local") { buttons[[paste0("conditions_",i)]] <- 1 }
} else {
showModal(modalDialog (uiOutput (paste0("no_quantiles_",i)), size="l"))
}
})
}
)
#same as above, for the test question
observeEvent(input[["enter_terts_0"]],{
# save inputs as reactive values
elici_t1[["test"]] <- input[["tertile1_0"]]
elici_t2[["test"]] <- input[["tertile2_0"]]
#check whether the plausible range is within parameter limits and elici_minis < elici_maxis
condition1 <- f_cond_min_max(elici_minis[["test"]], elici_maxis[["test"]], 0, NA)
# check whether quartiles are within plausible range and quartiles are in logical order
condition2 <- f_cond_tertiles(elici_minis[["test"]], elici_maxis[["test"]], elici_t1[["test"]], elici_t2[["test"]])
if(condition1 == 1 & condition2 == 1){
enter_terts[["test"]] <- 1
} else {
showModal(modalDialog (uiOutput ("no_quantiles_0"), size="l"))
}
})
if(save_method == "local" & elicitation_method == "chips and bins"){
conditions <- lapply(X = 1:tot_eli_ques, FUN = function(i){
reactive({
ifelse(sum(chips_chips[[eli_que_names[i]]]) < chips_nchip[[eli_que_names[i]]],
0,
1)
})
})
} else {
conditions <- lapply(X = 1:tot_eli_ques, FUN = function(i){
reactive({0})
})
}
names(conditions) <- paste0('que_', 1:tot_eli_ques)
# when expert is ready to move onto next question - save answers and change tab
lapply(X = 1:tot_eli_ques, FUN = function(i){
observeEvent(input[[paste0("next_que_",i)]], {
que_name <- eli_que_names[i]
if(elicitation_method == "chips and bins"){
if(sum(chips_chips[[que_name]]) < chips_nchip[[que_name]]){
# show error message if not all chips are used
showModal(modalDialog (uiOutput ("no_chips"), size="l"))
} else {
# save answers
temp2<-c(buttons$expert_id, elici_minis[[que_name]], elici_maxis[[que_name]], chips_value[[que_name]], chips_chips[[que_name]])
save[[paste0("next_que_", i)]] <- temp2
save[[paste0("next_que_", i, "_colnames")]] <- c("expert_id", paste0("que_",i,"_min"), paste0("que_",i,"_max"),
paste0("que_",i,"_bins_",1:((length(temp2)-2)/2)),
paste0("que_",i,"_chip_",1:((length(temp2)-2)/2)))
f_save_answers(save[[paste0("next_que_", i)]],
save[[paste0("next_que_", i, "_colnames")]],
paste0(buttons$expert_id,"_que_",i,".csv"))
if(paste0("comment_", i) %in% names(input)){
if(input[[paste0("comment_", i)]]!=""){
comments[[que_name]] <- input[[paste0("comment_", i)]]
f_save_answers(c(buttons$expert_id, comments[[que_name]]),
c("expert_id", paste0("que_", i, "_comment")),
paste0(buttons$expert_id, "_comment_que_", i, ".csv"))
}
}
if(tot_eli_ques > 1 & i < tot_eli_ques){
# if there are more questions to come, move onto the next question
buttons$que_no <- i + 1
} else {
# if this is the last question, show a pop up message
showModal(modalDialog (uiOutput ("end_of_exercise"), size="l"))
}
}
} else if (elicitation_method == "quartiles"){
# check whether the expert has updated their summary statements before proceeding
if(sum(c(paste0("min",i),
paste0("max",i),
paste0("quartile1_",i),
paste0("quartile1_",i),
paste0("quartile1_",i)) %in% names(input))==5){
if(elici_minis[[que_name]] == input[[paste0("min",i)]] &
elici_maxis[[que_name]] == input[[paste0("max",i)]] &
elici_q1[[que_name]] == input[[paste0("quartile1_",i)]] &
elici_q2[[que_name]] == input[[paste0("quartile2_",i)]] &
elici_q3[[que_name]] == input[[paste0("quartile3_",i)]]) {
condition3 <- 1
} else {
condition3 <- 0
}
} else {
condition3 <- 0
}
if(condition3 == 0){
showModal(modalDialog (uiOutput (paste0("update_values_",i)), size="l"))
} else {
# save answers
temp1 <- c(buttons$expert_id, elici_minis[[que_name]], elici_maxis[[que_name]], elici_q1[[que_name]], elici_q2[[que_name]], elici_q3[[que_name]])
save[[paste0("next_que_", i)]] <- temp1
save[[paste0("next_que_", i, "_colnames")]] <- c("expert_id",
paste0("que_",i,"_min"),
paste0("que_",i,"_max"),
paste0("que_",i,"_lower_quartile"),
paste0("que_",i,"_median"),
paste0("que_",i,"_upper_quartile"))
f_save_answers(save[[paste0("next_que_", i)]],
save[[paste0("next_que_", i, "_colnames")]],
paste0(buttons$expert_id,"_que_",i,".csv"))
if(paste0("comment_", i)%in%names(input)){
if(input[[paste0("comment_", i)]]!=""){
comments[[que_name]] <- input[[paste0("comment_", i)]]
f_save_answers(c(buttons$expert_id, comments[[que_name]]),
c("expert_id", paste0("que_", i, "_comment")),
paste0(buttons$expert_id, "_comment_que_", i, ".csv"))
}
}
if(tot_eli_ques > 1 & i < tot_eli_ques){
# if there are more questions to come, move onto the next question
buttons$que_no <- i + 1
} else {
# if this is the last question, show a pop up message
showModal(modalDialog (uiOutput ("end_of_exercise"), size="l"))
}
}
} else if (elicitation_method == "tertiles"){
if(sum(c(paste0("min",i),
paste0("max",i),
paste0("tertile1_",i),
paste0("tertile1_",i)) %in% names(input))==4){
if(elici_minis[[que_name]] == input[[paste0("min",i)]] &
elici_maxis[[que_name]] == input[[paste0("max",i)]] &
elici_t1[[que_name]] == input[[paste0("tertile1_",i)]] &
elici_t2[[que_name]] == input[[paste0("tertile2_",i)]]) {
condition3 <- 1
} else {
condition3 <- 0
}
} else {
condition3 <- 0
}
if(condition3 == 0){
showModal(modalDialog (uiOutput (paste0("update_values_",i)), size="l"))
} else {
# save answers
temp1 <- c(buttons$expert_id, elici_minis[[que_name]], elici_maxis[[que_name]], elici_t1[[que_name]], elici_t2[[que_name]])
save[[paste0("next_que_", i)]] <- temp1
save[[paste0("next_que_", i, "_colnames")]] <- c("expert_id",
paste0("que_",i,"_min"),
paste0("que_",i,"_max"),
paste0("que_",i,"_lower_tertile"),
paste0("que_",i,"_upper_tertile"))
f_save_answers(save[[paste0("next_que_", i)]],
save[[paste0("next_que_", i, "_colnames")]],
paste0(buttons$expert_id,"_que_",i,".csv"))
if(paste0("comment_", i)%in%names(input)){
if(input[[paste0("comment_", i)]]!=""){
comments[[que_name]] <- input[[paste0("comment_", i)]]
f_save_answers(c(buttons$expert_id, comments[[que_name]]),
c("expert_id", paste0("que_", i, "_comment")),
paste0(buttons$expert_id, "_comment_que_", i, ".csv"))
}
}
if(tot_eli_ques > 1 & i < tot_eli_ques){
# if there are more questions to come, move onto the next question
buttons$que_no <- i + 1
} else {
# if this is the last question, show a pop up message
showModal(modalDialog (uiOutput ("end_of_exercise"), size="l"))
}