-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.R
executable file
·1059 lines (1001 loc) · 32.7 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
# Load libraries ----
library(shiny)
library(shinyjs)
library(shinyBS)
library(shinyWidgets)
library(shinydashboard)
library(boastUtils)
library(dplyr)
# Define Global Constants ----
MAX_TRIES <- 4
WIN_STATE <- 10
GAME_OVER <- FALSE
# Load and shuffle question bank ----
rawBank <- read.csv(file = "questionBank.csv", header = TRUE)
# Define lists of discrete and continuous distributions ----
discDists <- rawBank %>%
dplyr::filter(type == "discrete") %>%
dplyr::select(distribution) %>%
dplyr::distinct(distribution) %>%
dplyr::arrange(distribution)
contDists <- rawBank %>%
dplyr::filter(type == "continuous") %>%
dplyr::select(distribution) %>%
dplyr::distinct(distribution) %>%
dplyr::arrange(distribution)
# Investigate these constants ----
numberRow <- numeric()
hint <- c()
correct_answer <- c()
# Define UI for App ----
ui <- list(
dashboardPage(
skin = "blue",
## Header ----
dashboardHeader(
title = "Matching Distributions",
titleWidth = 250,
tags$li(class = "dropdown", actionLink("info", icon("info"))),
tags$li(
class = "dropdown",
boastUtils::surveyLink(name = "Matching_Distributions")
),
tags$li(
class = "dropdown",
tags$a(href = 'https://shinyapps.science.psu.edu/', icon("home"))
)
),
## Sidebar ----
dashboardSidebar(
sidebarMenu(
id = "pages",
menuItem("Overview", tabName = "overview", icon = icon("tachometer-alt")),
menuItem("Prerequisites", tabName = "prerequisites", icon = icon("book")),
menuItem("Game", tabName = "game", icon = icon("gamepad")),
menuItem("References", tabName = "references", icon = icon("leanpub"))
),
tags$div(
class = "sidebar-logo",
boastUtils::sidebarFooter()
)
),
## Body ----
dashboardBody(
### Overview Page ----
tabItems(
tabItem(
tabName = "overview",
h1("Matching Distributions"),
p("In this App, you will gain practice at associating context with
different probability distributions."),
br(),
h2("Instructions"),
tags$ul(
tags$li(
"You will start this game with a little man on the top of a tree,
and you are trying to prevent his fall to the ground. If you
provide a wrong answer, he falls to a lower branch and eventually
to the ground. If you get 10 questions correct before he falls to
the ground, you have won the game and saved the little man!"
),
tags$li(
"Please select which probability distribution(s) you would like to
work on and hit the 'filter button."
),
tags$li(
"Read the given text and choose a distribution from the dropdown
menu. Make sure you understand the scenario."
),
tags$li(
"If you need some extra help, click the 'hint' button (shown as a
question mark symbol)."
),
tags$li(
"After you select the distribution, click 'Submit' to check your
answer. "
),
tags$li(
"Once you click 'Submit', you cannot revise your answer. You can
only click 'Next Question' to move on to your next challenge. "
),
tags$li(
"Before checking out the game page, be sure to review your
knowledge on the prerequisites page!"
)
),
div(
style = "text-align:center;",
bsButton(
inputId = "go",
label = "GO!",
icon("book"),
size = "large"
)
),
br(),
h3("Acknowledgements"),
p(
"This app was developed and coded by Zhiliang Zhang and futher
updated by Yiyang Wang, Yuqing Lei and Shravani Samala in 2021.",
br(),
br(),
br(),
"Cite this app as:",
br(),
boastUtils::citeApp(),
br(),
br(),
div(class = "updated", "Last Update: 10/8/2021 by NJH.")
)
),
### Prerequisites Page ----
tabItem(
tabName = "prerequisites",
withMathJax(),
h2("Prerequisites"),
p("In order to get the most out of this app, please review the
following:"),
tags$ul(
tags$li("Learn the difference between discrete distributions and
continuous distributions."),
tags$li("Learn what types of situations each probability distribution
is used for."),
tags$li("Review each distribution's parameters, pmf and/or cdf, mean,
variance, and moment-generating function in the ",
tags$a(
href = "https://psu-eberly.shinyapps.io/probability_applications/",
"Probability Applications",
class = "bodylinks"
),
"app's prerequisite page!")
),
h3("Discrete Distributions"),
p("For Discrete Distributions, data can only take on certain values in
a discrete set such as the whole numbers or integers."),
fluidRow(
box(
title = "Bernoulli",
status = "primary",
width = 6,
collapsible = TRUE,
collapsed = TRUE,
p(tags$strong("Model: "), "any situation where we can think of as
entailing a 'success' (typically coded as 1) and 'failure'
(everything that isn't a 'success', typically coded as 0).",
br(),
tags$strong("Example: "), "getting a 'heads' when flipping a coin."
)
),
box(
title = "Binomial",
status = "primary",
width = 6,
collapsible = TRUE,
collapsed = TRUE,
p(tags$strong("Model: "), "The number of 'successes' we see in a
fixed number of independent Bernoulli trials.",
br(),
tags$strong("Example: "), "how many 'heads' we get when we flip
a coin 10 times."
)
)
),
fluidRow(
box(
title = "Discrete Uniform",
status = "primary",
width = 6,
collapsible = TRUE,
collapsed = TRUE,
p(tags$strong("Model: "), "any situation where we believe that
statistical fairness holds; that is, we anticipate that each
individual outcome has the same probability of occurring.",
br(),
tags$strong("Example: "), "observing the top facing number when
rolling a standard, six-sided, fair, die."
)
),
box(
title = "Geometric",
status = "primary",
width = 6,
collapsible = TRUE,
collapsed = TRUE,
p(tags$strong("Model: "), "any situation where we are tracking how
many independent trials we conduct before we observe the first
success.",
br(),
tags$strong("Example: "), "how many times you have to flip a coin
until you first get 'heads'."
)
)
),
fluidRow(
box(
title = "Hypergeometric",
status = "primary",
width = 6,
collapsible = TRUE,
collapsed = TRUE,
p(tags$strong("Model: "), "any situation where we first imagine a
collection of ", tags$em("N"), " total items. In this collection
there are ", tags$em("m"), " type 1 items and ", tags$em("N - m"),
" type 2 items. We then imagine randomly selecting ", tags$em("n"),
" items without replacement from the collection.",
br(),
tags$strong("Example: "), "a bowl contains 30 red marbles and
60 black marbles. You randomly choose 15 marbles from the
bowl. The number of black marbles in this sample follows a
hypergeometric distribution."
)
),
box(
title = "Negative Binomial",
status = "primary",
width = 6,
collapsible = TRUE,
collapsed = TRUE,
p(tags$strong("Model: "), "any situation where we are tracking how
many independent trials we conduct before we observe the ",
tags$em("k"), "-th success.",
br(),
tags$strong("Example: "), "how many times you have to flip a coin
until you get ten 'heads'."
)
)
),
fluidRow(
box(
title = "Poisson",
status = "primary",
width = 6,
collapsible = TRUE,
collapsed = TRUE,
p(tags$strong("Model: "), "any situation where we are interested in
the how many times we observe a rare event (the event's count) in
a fixed amount of time or space.",
br(),
tags$strong("Example: "), "the number of fatal scuba diving
accidents in Australia next year."
)
)
),
h3("Continuous Distributions"),
p("For Continuous Distributions, data can take on values from a
continuum."),
fluidRow(
box(
title = "Beta",
status = "primary",
width = 6,
collapsible = TRUE,
collapsed = TRUE,
p(tags$strong("Model: "), "the specific rank of fixed number of
independent standard uniforms.",
br(),
tags$strong("Example: "), "the median of five trials for the
proportion of the way around a circle that a spinner lands."
)
),
box(
title = "Continuous Uniform",
status = "primary",
width = 6,
collapsible = TRUE,
collapsed = TRUE,
p(tags$strong("Model: "), "when we imagine the probability spread
evenly (uniformly) over the continuum.",
br(),
tags$strong("Example: "), "the measure of the angle swept out by
the spinner from a fixed reference point."
)
)
),
fluidRow(
box(
title = "Exponential",
status = "primary",
width = 6,
collapsible = TRUE,
collapsed = TRUE,
p(tags$strong("Model: "), "the time until the next independent and
rare event.",
br(),
tags$strong("Example: "), "how long until the next fatal scuba
diving accident occurs in Australia."
)
),
box(
title = "Gamma",
status = "primary",
width = 6,
collapsible = TRUE,
collapsed = TRUE,
p(tags$strong("Model: "), "the time until the ", tags$em("k"), "-th
rare independent event occurs.",
br(),
tags$strong("Example: "), "how long until there have been ten
fatal scuba diving accidents occur in Australia."
)
)
),
fluidRow(
box(
title = "Normal",
status = "primary",
width = 6,
collapsible = TRUE,
collapsed = TRUE,
p(tags$strong("Model: "), "sum or [arithmetic] mean from a large
sample.",
br(),
tags$strong("Example: "), "the [arithmetic] mean income of a
random sample of 1000 people."
)
)
),
div(
style = "text-align:center;",
bsButton(
inputId = "go2",
label = "GO!",
icon("gamepad"),
size = "large"
)
)
),
### Game Page ----
tabItem(
tabName = "game",
withMathJax(),
h2("Matching Distributions Game"),
p("Identify the appropriate distribution based upon the context
provided. To win, you will need to correctly identify ", WIN_STATE,
" distributions before the man falls to the ground. Each time you
incorrectly guess, he will move down a branch; you make at most ",
MAX_TRIES, " mistakes."),
hr(),
h3("First, Select Your Distributions"),
p("Please select the distributions you'd like to use for this game and
then click the 'Filter' button to begin."),
fluidRow(
column(
width = 2,
offset = 0,
dropdownButton(
inputId = "discreteDropdown",
label = "Discrete distributions",
size = "lg",
circle = FALSE,
status = "default",
width = "100%",
tags$div(
bsButton(
inputId = "selectAllD",
label = "Unselect",
size = "small"
),
checkboxGroupInput(
inputId = "discreteList",
label = "Discrete distributions",
choices = discDists$distribution,
selected = discDists$distribution
)
)
)
),
column(
width = 2,
offset = 1,
dropdownButton(
inputId = "continuousDropdown",
label = "Continuous distributions",
circle = FALSE,
size = "lg",
status = "default",
width = "100%",
tags$div(
bsButton(
inputId = "selectAllC",
label = "Unselect",
size = "small"
),
checkboxGroupInput(
inputId = "continuousList",
label = "Continuous distributions",
choices = contDists$distribution,
selected = contDists$distribution
)
)
)
),
column(
width = 2,
offset = 1,
bsButton(
inputId = "filter",
label = "Filter",
size = "large",
style = "primary",
disabled = FALSE
)
)
),
hr(),
h3("Play the Game"),
fluidRow(
column(
width = 5,
offset = 0,
wellPanel(
p("Your current context:"),
uiOutput("question"),
fluidRow(
column(
width = 3,
bsButton(
inputId = "hint",
label = "Hint",
icon = icon("question"),
size = "large",
type = "toggle",
disabled = TRUE
)
),
column(
width = 9,
uiOutput("hintDisplay")
)
),
selectInput(
inputId = "answer",
label = "Select the matching distribution",
choices = "",
selected = "",
width = "100%"
),
fluidRow(
column(
width = 3,
bsButton(
inputId = "submit",
label = "Submit",
size = "large",
style = "default",
disabled = TRUE
)
),
column(
width = 1,
uiOutput("mark")
)
),
uiOutput("feedback"),
br(),
fluidRow(
column(
width = 4,
bsButton(
inputId = "nextq",
label = "Next Question",
size = "large",
style = "success",
disabled = TRUE
)
),
column(
width = 4,
offset = 1,
bsButton(
inputId = "restart",
label = "Restart the game",
size = "large",
style = "warning",
disabled = FALSE
)
)
)
)
),
column(
width = 7,
offset = 0,
uiOutput("correctCount", align = "center"),
uiOutput("gameProgress", align = "center")
)
)
),
### References Page ----
tabItem(
tabName = "references",
withMathJax(),
h1("References"),
p(
class = "hangingindent",
"Attali, D. (2020). shinyjs: Easily Improve the User Experience of
Your Shiny Apps in Seconds. R package version 1.1. Available from
https://CRAN.R-project.org/package=shinyjs"
),
p(
class = "hangingindent",
"Bailey, E. (2015). shinyBS: Twitter bootstrap components for shiny.
(v0.61). [R package]. Available from
https://CRAN.R-project.org/package=shinyBS"
),
p(
class = "hangingindent",
"Carey, R. and Hatfield, N. (2020). boastUtils: BOAST Utilities.
R package version 0.1.6.3. Available from
https://github.com/EducationShinyAppTeam/boastUtils"
),
p(
class = "hangingindent",
"Chang, W. and Borges Ribeiro, B. (2018). shinydashboard:
Create Dashboards with 'Shiny'. R package version 0.7.1. Available
from https://CRAN.R-project.org/package=shinydashboard"
),
p(
class = "hangingindent",
"Chang, W., Cheng, J., Allaire, J., Xie, Y., and McPherson, J.
(2020). shiny: Web Application Framework for R. R package version
1.5.0. Available from https://CRAN.R-project.org/package=shiny"
),
p(
class = "hangingindent",
"Introduction to STAT 414.” PennState Eberly College of Science,
online.stat.psu.edu/stat414/lesson/introduction-stat-414."
),
p(
class = "hangingindent",
"Perrier, V., Meyer, F., and Granjon, D. (2020). shinyWidgets:
Custom Inputs Widgets for Shiny. R package version 0.5.3. Available
from https://CRAN.R-project.org/package=shinyWidgets"
),
p(
class = "hangingindent",
"Wickham, H., François, R., Henry, L., and Müller, K. (2021). dplyr:
A Grammar of Data Manipulation. R package version 1.0.7. Available
from https://CRAN.R-project.org/package=dplyr"
),
br(),
br(),
br(),
boastUtils::copyrightInfo()
)
)
)
)
# Define server logic ----
server <- function(session, input, output) {
## User variables ----
chosenDists <- reactiveVal(NULL)
filteredQuestions <- reactiveVal()
rowNumber <- reactiveVal(0)
score <- reactiveVal(0)
mistakes <- reactiveVal(0)
## Info button ----
observeEvent(
eventExpr = input$info,
handlerExpr = {
sendSweetAlert(
session = session,
title = "Instructions",
text = "After selecting which distributions you want to practice and
clicking Filter, carefully read through the provided context. Then select
the distribution that best matches what's happening.",
type = "info"
)
})
## Go button overview to prerequisites----
observeEvent(
eventExpr = input$go,
handlerExpr = {
updateTabItems(
session = session,
inputId = "pages",
selected = "prerequisites")
})
## Go button prerequisites to challenge----
observeEvent(
eventExpr = input$go2,
handlerExpr = {
updateTabItems(
session = session,
inputId = "pages",
selected = "game")
})
## Select all discrete ----
observeEvent(
eventExpr = input$selectAllD,
handlerExpr = {
if (input$selectAllD == 0) {
updateButton(
session = session,
inputId = "selectAllD",
label = "Unselect"
)
updateCheckboxGroupInput(
session,
"discreteList",
choices = discDists$distribution,
selected = discDists$distribution
)
} else if (input$selectAllD %% 2 == 1) {
updateButton(
session = session,
inputId = "selectAllD",
label = "Select All")
updateCheckboxGroupInput(
session = session,
inputId = "discreteList",
choices = discDists$distribution
)
} else {
updateButton(
session = session,
inputId = "selectAllD",
label = "Unselect")
updateCheckboxGroupInput(
session = session,
inputId = "discreteList",
choices = discDists$distribution,
selected = discDists$distribution
)
}
}
)
## Select all continuous ----
observeEvent(
eventExpr = input$selectAllC,
handlerExpr = {
if (input$selectAllC == 0) {
updateButton(
session = session,
inputId = "selectAllC",
label = "Unselect")
updateCheckboxGroupInput(
session = session,
inputId = "continuousList",
choices = contDists$distribution,
selected = contDists$distribution
)
} else if (input$selectAllC %% 2 == 1) {
updateButton(
session = session,
inputId = "selectAllC",
label = "Select All")
updateCheckboxGroupInput(
session = session,
inputId = "continuousList",
choices = contDists$distribution
)
} else {
updateButton(
session = session,
inputId = "selectAllC",
label = "Unselect")
updateCheckboxGroupInput(
session = session,
inputId = "continuousList",
choices = contDists$distribution,
selected = contDists$distribution
)
}
})
## Filter button ----
observeEvent(
eventExpr = input$filter,
handlerExpr = {
### Enable buttons: hint, submit ----
updateButton(
session = session,
inputId = "hint",
disabled = FALSE
)
updateButton(
session = session,
inputId = "submit",
disabled = FALSE
)
### Filter question bank ----
chosenDists(c(input$discreteList, input$continuousList))
#### Error check
if (is.null(chosenDists())) {
sendSweetAlert(
session = session,
title = "No Distributions Selected",
text = "You've not selected any distributions to review. Please select
at least one distribution.",
type = "error"
)
} else {
updateSelectInput(
session = session,
inputId = "answer",
label = NULL,
choices = c("Select a distribution", chosenDists()),
selected = NULL
)
questionBank <- rawBank %>%
dplyr::slice_sample(prop = 1)
filteredQuestions(
questionBank %>%
dplyr::filter(distribution %in% chosenDists())
)
### Do we really want this here?
rowNumber(1)
output$question <- renderUI({
withMathJax(p(filteredQuestions()$context[rowNumber()]))
})
}
stmt <- boastUtils::generateStatement(
session,
object = "filter",
verb = "interacted",
description = "Please select the distributions you'd like to use in this app and click Filter",
response = paste(chosenDists(), sep = ", ", collapse = ", ")
)
boastUtils::storeStatement(session, stmt)
},
ignoreNULL = TRUE,
ignoreInit = TRUE
)
## Submit button ----
observeEvent(
eventExpr = input$submit,
handlerExpr = {
### Check for valid response on submit ----
if (is.null(input$answer) || input$answer == "Select a distribution") {
sendSweetAlert(
session = session,
title = "Select an answer",
text = "Be sure to select a distribution from the drop down menu
before you click the submit button.",
type = "error"
)
} else {
#### Disable self and hint buttons ----
updateButton(
session = session,
inputId = "hint",
disabled = TRUE
)
updateButton(
session = session,
inputId = "submit",
disabled = TRUE
)
#### Score choice ----
success <- input$answer == filteredQuestions()$distribution[rowNumber()]
if (success) {
score(score() + 1)
output$mark <- boastUtils::renderIcon(icon = "correct")
} else {
mistakes(mistakes() + 1)
output$mark <- boastUtils::renderIcon(icon = "incorrect")
}
#### Display feedback ----
output$feedback <- renderUI({
withMathJax(p(filteredQuestions()$feedback[rowNumber()]))
})
stmt <- boastUtils::generateStatement(
session,
object = "submit",
verb = "answered",
description = filteredQuestions()$context[rowNumber()],
response = input$answer,
interactionType = "choice",
success = success,
completion = score() == WIN_STATE
)
boastUtils::storeStatement(session, stmt)
}
### Check if game has been won or lost ----
if (score() == WIN_STATE) {
sendSweetAlert(
session = session,
title = "Congrats!",
text = "You have won the game!",
type = "success"
)
stmt <- boastUtils::generateStatement(
session = session,
object = "game",
verb = "completed",
description = "Player has won the game.")
boastUtils::storeStatement(session, stmt)
} else if (mistakes() == MAX_TRIES) {
sendSweetAlert(
session = session,
title = "Try Again",
text = "The man fell to the ground. Please try again.",
type = "error"
)
stmt <- boastUtils::generateStatement(
session = session,
object = "game",
verb = "completed",
description = "Player has lost the game.")
boastUtils::storeStatement(session, stmt)
} else {
#### Enable next question
updateButton(
session = session,
inputId = "nextq",
disabled = FALSE
)
}
})
## Next question button ----
observeEvent(
eventExpr = input$nextq,
handlerExpr = {
### Clear feedback displays ----
output$mark <- renderIcon()
output$hintDisplay <- NULL
output$feedback <- NULL
### Reset answer selection ----
updateSelectInput(
session = session,
inputId = "answer",
selected = "Select a distribution"
)
### Move through question bank ----
if (rowNumber() >= nrow(filteredQuestions())) {
sendSweetAlert(
session = session,
title = "Out of Questions",
text = "Unfortunately, we've run out of questions. Please restart the
game and/or include more distributions to practice with.",
type = "error"
)
} else {
rowNumber(rowNumber() + 1)
#### Enable buttons ----
updateButton(
session = session,
inputId = "hint",
disabled = FALSE
)
updateButton(
session = session,
inputId = "submit",
disabled = FALSE
)
}
updateButton(
session = session,
inputId = "nextq",
disabled = TRUE
)
},
ignoreNULL = TRUE,
ignoreInit = TRUE
)
## Restart button ----
observeEvent(
eventExpr = input$restart,
handlerExpr = {
### Clear feedback displays ----
output$mark <- renderIcon()
output$hintDisplay <- NULL
output$feedback <- NULL
### Reset answer selection ----
updateSelectInput(
session = session,
inputId = "answer",
choices = c("Select a distribution"),
selected = "Select a distribution"
)
### Disable buttons ----
updateButton(
session = session,
inputId = "hint",
disabled = TRUE
)
updateButton(
session = session,
inputId = "submit",
disabled = TRUE
)
updateButton(
session = session,
inputId = "nextq",
disabled = TRUE
)
### Reset filters ----
updateButton(
session = session,
inputId = "selectAllD",
label = "Unselect"
)
updateButton(
session = session,
inputId = "selectAllC",
label = "Unselect"
)
updateCheckboxGroupInput(
session = session,
inputId = "discreteList",
selected = discDists$distribution
)
updateCheckboxGroupInput(
session = session,
inputId = "continuousList",
selected = contDists$distribution
)
### Clear user variables ----
chosenDists(NULL)
filteredQuestions(NULL)
rowNumber(0)
score(0)
mistakes(0)
stmt <- boastUtils::generateStatement(
session = session,
object = "restart",
verb = "interacted",
description = "Game has been restarted.")
boastUtils::storeStatement(session, stmt)
},
ignoreNULL = TRUE,
ignoreInit = TRUE
)
## Reactive display objects ----
### Display base question prompt ----
output$question <- renderUI({
if (rowNumber() == 0) {
output$question <- renderUI({
p("Select distributions to review and then press Filter.")
})
}
})
### Display hint ----
observeEvent(