Quizzes and exercises for Quarto websites
Motivation
I am currently using Quarto for my course websites. Sometimes, it’s useful to include interactive exercises or quizzes. I was looking around to find something that fits my needs. Ideally, what I want is:
- Easy to set up and implement/use
- No need to run server-side software
- Well maintained
- Programming language idependent
- Definitely support multiple choice questions, if also supports coding exercises/questions, even better.
I figured I write down what I explored. Mostly for my future self who won’t be able to remember any of that in a few weeks 1. And maybe others find it useful too.
TLDR
Based on what I was able to find, the most suitable option for my purpose seems to be the exams
R package, and its new sister package exams2forms
which allows integration of questions into websites.
Those packages can’t do coding exercises, so if a future version of some of the webR
framework based implementations described below make multiple-choice questions easy to implement, I would prefer to use them.
Previously
Shiny/learnr
In the old days, there was nothing much for interactive web-based quizzes/exercises (in the R language space). Then came Shiny
, which allowed interactive websites. Building on top of that, along came the learnr
R package which allows nice implementation of exercises and quizzes on websites.
A colleague and I developed a set of learnr
/Shiny
tutorials for our interactive Introductory Biostatistics Labs in R. We currently still use these labs as part of a course we regulary teach. (You can see the labs in action here.)
This setup works overall well. The main drawback is that one needs to deploy the content to a Shiny
server. That can be costly and/or somewhat tricky to administer. Another current disadvantage with learnr
is that development has slowed down (ceased?). The GitHub page shows open pull requests from 5 years ago, over 100 open issues, and only 3 commits in 2024. Posit (formerly RStudio) folks, who were the main developers of learnr
, seem to have moved on to newer things (see below.)
Other options
The R package webexercises
provides some simple functionality to embed quizzes in websites. It can’t do coding exercises, but is nice for simple multi-choice/true-false and similar questions. The main potential drawbacks are that questions need to be written as R code, and that package development and maitenance doesn’t seem very active. The last commit was about 2 years ago, and there are several open GitHub PRs and Issues. If something were to break/not work (I’ve noticed occasional iffy behaviour in my explorations), it’s unclear if things would be addressed by the maintainer2.
Something similar to webexercises
is the checkdown
R package. It has very similar functionality, and I have exactly the same robustness/maintenance concerns for this package that I have for webexercises
. The prolific (and way more technically savy than me) Andrew Heiss uses checkdown
for his R Studio Primer port. That makes me a bit confident that if I were to use this package and something went wrong, I could ask him for a hack/fix 😁.
Another exercise/quiz/exam focused package that has been around for a while is exams
. They have a new package called exams2forms
which allows integration of questions into websites. The whole package seems fairly full-featured and initially a bit intimidating, but after reading the tutorials, I realized it’s not that difficult. I experimented with it, and it seems to work well. The developers/maintainers are highly active, so my concerns regarding future support are minimal. I’m giving a quick worked example using exams
below.
New Stuff
Recent developments in the R/Quarto space are of course continued improvement of Quarto itself, and the webR framework, which allows running R code in the browser. There are several options for potential exercise/quiz implementations.
Quarto based
Quarto allows individuals to write extensions that supply additional functionality. I’m aware of two that implement some form of quiz/exercise functionality. The first, quarto-quiz
only works for the revealJS
format, so is not suitable for html-based websites.
The second, naquiz
can be included within html websites. Possible advantages of this package is that the quizzes are programming-language agnostic, and implementing simple questions is rather easy. The main hesitation I have is again robustness/maintenance. The package has a single developer/maintainer, the extension hasn’t been updated in over 2 years. There’s an open GitHub issue filed in Sept 2024 with what seems like a somewhat serious and simple to fix bug that has not been addressed. This makes me wonder as a user how likely any issues I might run into would be addressed.
webR based
There are several new options that make use of the new webR
framework to allow one to run interactive coding exercises inside Quarto documents/websites, without needing a Shiny server on the backend.
quarto-webr
is one such option, quarto-live
is an alternative, very similar option. As far as I can tell these two options provide roughly similar functionality3. They are meant to allow execution of code - and exercises based on code - being run in the browser without the need for an R/Shiny server. A related package, shinylive
, provides somwhat similar functionality (R/Shiny without a server) but is not as Quarto focused.
The main drawback (for me) is that these packages do not - as far as I can tell - provide any user-friendly and simple options to implement non-coding exercises, such as simple multiple choice or true-false questions. Another, minor inconvenience is that they are R code based, but as long as the code can be hidden from the user, I’d be ok with that.
If someone were to implement an easy way to write non-coding quiz questions using either of those approaches, it would likely be ideal for me since then I could use the same approach for classes where I want to show/do coding exercises and for those where I only want to have interactive quiz functionality. I guess I basically want a re-implementation of learnr
using the webR
framework to allow deployment on static websites. Alas, that does not currently seem to exist4.
Summary
In conclusion, based on what I found online, I can’t exactly have what I want (learnr
functionality, such as easy creation of simple quizzes, in a webR
setting). Since my immediate needs are not for coding exercises but quizzes, I plan to use exams
and exams2forms
.
In the meantime, I’ll keep checking every so often, maybe someone will develop what I’m looking for, a full-featured exercise/quiz system based on R/Shiny in the browser (and maybe with the option to toggle between languages, personally I would like to see Julia support the most, I care less about Python).
Further resources
- The
quarto-webr
website has a nice list of examples of folks using that setup for teaching.
Acknowledgments
I want to acknowledge all those folks generating the tools I describe above - even if a this point, none areexactly doing what I’m looking for 😁.
A brief exams
example
The following shows a simple example of making and embedding questions into a Quarto website using exams
and exams2forms
.
Step 1: Install the packages and any other tools. Then read the First Steps Tutorial for the main exams
package and the exams2forms
tutorial.
Step 2: Write up each question as an Rmd
file following their provided templates/examples. Here’s a simple example:
Question
========
Which of these is NOT a component of a READy workflow?
(See here: https://andreashandel.github.io/MADAcourse/content/module-ready-workflow/ready-overview.html)
Answerlist
----------
* Reproducible
* Efficient
* Analytical
* Documented
Solution
========
READy stands for: Reproducible, efficient, automated, and documented
Answerlist
----------
* False
* False
* True
* False
Meta-information
================
exname: test quiz
extype: schoice
exsolution: 0010
Step 3: Load that question inside your Quarto document with code like this:
Which of these is NOT a component of a READy workflow? (See here: https://andreashandel.github.io/MADAcourse/content/module-ready-workflow/ready-overview.html)
READy stands for: Reproducible, efficient, automated, and documented
- False
- False
- True
- False
Or do an inline question with code like this:
Which of these is the most fun sport?
Which is created by this bit of code:
`r exams2forms::forms_schoice(c("Cricket", "Soccer", "Mountain Biking", "Synchronized Swimming"), c(FALSE, FALSE, TRUE, FALSE), display = "dropdown")`
Step 4: Add their css and js files to Quarto as described in the tutorial, then re-render everything.
Footnotes
Just the other day I wanted to know how to customize Quarto callouts and a quick Google search turned up a helpful blogpost that seemed vaguely familiar 😂. Turns out I had the same question and figured it out about 2 years ago - I’m getting old 🙄.↩︎
I’m certainly not here to criticize any volunteer software development/maintenance work! I know from my own R package development that things like software maintenance are rarely rewarded bye one’s main employer and therefore often need to be low priority. I’m just making a comment as a user who is thinkinng about robustness/sustainability for my courses.↩︎
Without having actually tried each, that’s just my impression after reading through some of the documentation.↩︎
It seems to be possible to do it, but that approach looks too involved and complex to me.↩︎