Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow down successive exercise execution via debounce #814

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# learnr (development version)

- Added option `tutorial.exercise.debounce` to slow down successive exercise execution (@internaut)
schloerke marked this conversation as resolved.
Show resolved Hide resolved
- Removed dependency on ellipsis (@olivroy, #809)
- Added Norwegian translation contributed by @jonovik. (#806)

Expand Down
6 changes: 5 additions & 1 deletion R/exercise.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ 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_ms <- getOption("tutorial.exercise.debounce", 0) # value in milliseconds
if (debounce_ms > 0)
exercise_rx <- debounce(exercise_rx, debounce_ms)
schloerke marked this conversation as resolved.
Show resolved Hide resolved

# observe input
observeEvent(exercise_rx(), {

# get exercise from app
exercise <- exercise_rx()
# Add tutorial information
Expand Down
2 changes: 2 additions & 0 deletions pkgdown/assets/snippets/exercisedebounce.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# set debounce time to 1 second:
schloerke marked this conversation as resolved.
Show resolved Hide resolved
options("tutorial.exercise.debounce" = 1000)
schloerke marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions vignettes/articles/exercises.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ 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 milliseconds) that is waited before the next code execution is performed:
schloerke marked this conversation as resolved.
Show resolved Hide resolved

```{r snippet-exercisedebounce, echo = FALSE}
insert_snippet("exercisedebounce")
```

## Exercise Setup {#exercise-setup}

Code chunks with `exercise=TRUE` are evaluated within standalone environments.
Expand Down