diff --git a/NEWS.md b/NEWS.md index b7b25e98..a2ca912a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # learnr (development version) -- Added a new option, `tutorial.exercise.debounce`, to slow down successive exercise execution. This option should be set to the number of seconds a user will have to wait before their next code execution is performed. The option defaults to 1 second to deter rapid code executions. To disable this behavior, call `options(tutorial.exercise.debounce = 0)` within your setup chunk. (@internaut, #818) +- Added a new option, `tutorial.exercise.throttle`, to slow down successive exercise execution. This option should be set to the number of seconds a user will have to wait between performing code executions. The option defaults to 1 second to deter rapid code executions. To disable submission throttling, call `options(tutorial.exercise.throttle = 0)` within your setup chunk. (@internaut, #818) - Removed dependency on ellipsis (@olivroy, #809) diff --git a/R/exercise.R b/R/exercise.R index c2726b1e..fbf280ff 100644 --- a/R/exercise.R +++ b/R/exercise.R @@ -33,10 +33,10 @@ setup_exercise_handler <- function(exercise_rx, session) { # setup reactive values for return rv <- reactiveValues(triggered = 0, result = NULL) - # debounce option to slow down successive exercise execution requests - debounce_s <- getOption("tutorial.exercise.debounce", 1) # in seconds - if (is.numeric(debounce_s) && debounce_s > 0) { - exercise_rx <- debounce(exercise_rx, debounce_s * 1000) # in milliseconds + # throttle option to slow down successive exercise execution requests + throttle_s <- getOption("tutorial.exercise.throttle", 1) # in seconds + if (is.numeric(throttle_s) && throttle_s > 0) { + exercise_rx <- throttle(exercise_rx, throttle_s * 1000) # in milliseconds } # observe input observeEvent(exercise_rx(), { diff --git a/vignettes/articles/exercises.Rmd b/vignettes/articles/exercises.Rmd index b3147ffd..d842388e 100644 --- a/vignettes/articles/exercises.Rmd +++ b/vignettes/articles/exercises.Rmd @@ -80,18 +80,18 @@ This option can also be set either globally or per-chunk: insert_snippet("exerciseeval") ``` -It may be necessary to slow down successive exercise submissions, otherwise users may overwhelm your server by running exercise code chunks in fast repetition. You can do so globally by setting the option `tutorial.exercise.debounce` to an amount of time (in seconds) that is waited before the same user's next code execution is performed. This option is set to 1 second by default. +To prevent server overload caused by users rapidly clicking the "Run Code" button, you can set a delay between exercise code submissions using the `tutorial.exercise.throttle` option (in seconds). This will ensure that the same user can only start the evaluation of the same exercise per `tutorial.exercise.throttle` seconds. This option is set globally and the default is a throttle of of 1 second. -```{r snippet-exercisedebounce, eval = FALSE} -# Set exercise submission debounce time to 5 seconds -options("tutorial.exercise.debounce" = 5) +```{r snippet-exercisethrottle, eval = FALSE} +# Set exercise submission throttle time to 5 seconds +options("tutorial.exercise.throttle" = 5) ``` To disable of this behavior, you can set the option to 0: -```{r snippet-exercisedebounceoff, eval = FALSE} -# Disable exercise submission debounce -options("tutorial.exercise.debounce" = 0) +```{r snippet-exercisethrottleoff, eval = FALSE} +# Disable exercise submission throttle +options("tutorial.exercise.throttle" = 0) ``` ## Exercise Setup {#exercise-setup}