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

feat: Slow down successive (same) exercise execution via throttle #818

Merged
merged 13 commits into from
Sep 4, 2024
18 changes: 9 additions & 9 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: windows-latest, r: '3.6'}
- {os: ubuntu-20.04, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-20.04, r: 'release'}
- {os: ubuntu-20.04, r: 'oldrel-1'}
- {os: ubuntu-20.04, r: 'oldrel-2'}
- {os: ubuntu-20.04, r: 'oldrel-3'}
- {os: ubuntu-20.04, r: 'oldrel-4'}
- { os: macOS-latest, r: "release" }
- { os: windows-latest, r: "release" }
# - {os: windows-latest, r: '3.6'} # Difficulty building packages on windows w/ R 3.6
schloerke marked this conversation as resolved.
Show resolved Hide resolved
- { os: ubuntu-20.04, r: "devel", http-user-agent: "release" }
- { os: ubuntu-20.04, r: "release" }
- { os: ubuntu-20.04, r: "oldrel-1" }
- { os: ubuntu-20.04, r: "oldrel-2" }
- { os: ubuntu-20.04, r: "oldrel-3" }
- { os: ubuntu-20.04, r: "oldrel-4" }

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ Config/Needs/coverage: covr
Config/Needs/website: pkgdown, tidyverse/tidytemplate
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
SystemRequirements: pandoc (>= 1.14) - http://pandoc.org
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 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. (@internaut, #818)
- 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_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
}
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 exercise submission debounce time to 1 second
options("tutorial.exercise.debounce" = 1)
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 seconds) that is waited before the same user's next code execution is performed:

```{r snippet-exercisedebounce, echo = FALSE}
insert_snippet("exercisedebounce")
```
schloerke marked this conversation as resolved.
Show resolved Hide resolved

## Exercise Setup {#exercise-setup}

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