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

Get timelimit from complete exercise object #494

Merged
merged 3 commits into from
Feb 17, 2021

Conversation

gadenbuie
Copy link
Member

@gadenbuie gadenbuie commented Feb 16, 2021

Edit: on second thought, we were just setting timelimit too early. Getting the timelimit after filling out the exercise object fixes the issue in #492.

This fixes #492. The exercise reactive returned by input$`tutorial-exercise-%s-code-editor` doesn't include all of the exercise options. It seems that exercise_rx() only contains the label, the submitted code, a timestamp and flags for restore and should_check. The result is that, when setup_exercise_handler tries to find $options$exercise.timelimit, that field is always NULL because $options isn't a item in the reactive exercise list.

I'm not sure if that should be rectified in the exercise object logic, but I was able to fix the issue by merging the reactive exercise object with the cached exercise object that contains the complete options, check code, etc. (Edit: which we do later so we were just setting timelimit too eary.)

Here's a reprex Rmd for testing. Prior to the change in this PR, learnr ignores both the chunk and global options and always caps exercises at 30 seconds. Both time-limit setting methods are demonstrated in the reprex.

---
title: "Tutorial"
output: learnr::tutorial
runtime: shiny_prerendered
---

```{js, echo=FALSE}
// custom message handler to report elapsed time
Shiny.addCustomMessageHandler('time', function(x) {
  document.getElementById('section-time').textContent = x
})
```

## Time Limit

```{r setup}
library(learnr)
tutorial_options(exercise.timelimit = 15)
```

The code has been running for <span id="time">0</span> seconds.

```{r ex-setup}
sleep <- function(n) {
  session <- shiny::getDefaultReactiveDomain()
  session$sendCustomMessage("time", 0)
  for (i in 1:n) {
    Sys.sleep(1)
    session$sendCustomMessage("time", i)
  }
}
```

```{r ex, exercise = TRUE, exercise.timelimit = 5}
sleep(15)
```

PR task list:

  • Update NEWS
  • Add tests (if possible)
  • Update documentation with devtools::document()

@gadenbuie gadenbuie changed the title Merge cached exercise with reactive exercise submission Get timelimit from complete exercise object Feb 17, 2021
@gadenbuie gadenbuie merged commit 7473563 into rstudio:master Feb 17, 2021
@gadenbuie gadenbuie deleted the fix-492 branch February 17, 2021 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

is "exercise.timelimit" working?
2 participants