This directory contains interactive learnr quizzes for the openwashdata course and a landing page to access them.
Live Demo: https://hjj91u-nicolo-massari.shinyapps.io/openwashdata-quiz-hub/
app.R- Quiz landing page that automatically displays all configured quizzesbuild.R- Deployment script with helper functions for automated deploymentconfig.R- Shared configuration file defining all available quizzesmodules/- Directory containing all quiz filesmd-01-quiz.Rmd- Module 1 quiz on Quarto basics (learnr tutorial)_github_username.Rmd- Reusable component for GitHub username input with CSV data_submission.Rmd- Reusable component for quiz submissiongithub_usernames.csv- Student GitHub username database- Additional quiz files can be added as
md-XX-quiz.Rmd
Make sure these packages are installed:
All required packages are defined in DESCRIPTION and automatically installed during deployment. For local development:
# Install from DESCRIPTION file
devtools::install_github("ds4owd-dev/quiz")Before deploying, you need to authenticate with shinyapps.io:
- Get your account credentials from https://www.shinyapps.io/admin/#/tokens
- Set up authentication in R:
rsconnect::setAccountInfo(
name = 'your-account-name',
token = 'YOUR-TOKEN-HERE',
secret = 'YOUR-SECRET-HERE'
)Replace your-account-name, YOUR-TOKEN-HERE, and YOUR-SECRET-HERE with your actual credentials.
The quizzes now include automatic submission to Google Forms for tracking student progress:
- GitHub username collection: Students enter their GitHub username at the start
- Learnrhash generation: Quiz responses are encoded using learnrhash
- Automatic submission: Results are submitted to Google Form via POST request
- Modular components: Reusable username and submission components
To connect quizzes to your own Google Form, update the configuration in modules/_submission.Rmd.
Your Google Form should have exactly 3 questions:
- Tutorial/Module ID (text field)
- GitHub username (text field)
- Learnrhash (long text field for quiz results)
To get the entry IDs for your form fields:
- Open your Google Form (the live form, not edit mode)
- Open browser inspector (F12 or right-click → Inspect)
- Search for "entry" in the HTML (Ctrl+F)
- Copy the entry IDs - they appear as
entry.1234567890
The entry IDs will be in the order your questions are set up in the form.
Update the variables at the top of modules/_submission.Rmd:
# Google Form setup
form_url <- "https://docs.google.com/forms/d/e/YOUR-FORM-ID/formResponse"
# Entry ID mappings
tutorial_id_entry_id <- "entry.YOUR-MODULE-ID" # For module name
github_username_entry_id <- "entry.YOUR-USERNAME-ID" # For GitHub username
learnrhash_entry_id <- "entry.YOUR-LEARNRHASH-ID" # For quiz results- Form URL: https://docs.google.com/forms/d/e/1FAIpQLScnw9R8wMU5SfFqNVXGeEkiIygLTB_Dc6jWBmbwEeHuekBDzg/formResponse
- Entry IDs:
entry.1169139257- Module name (1st question)entry.61564704- GitHub username (2nd question)entry.1315905314- Learnrhash (3rd question)
Quizzes are automatically deployed to shinyapps.io via GitHub Actions when changes are pushed to the main or dev branches.
-
Get shinyapps.io credentials:
- Go to shinyapps.io → Account → Tokens
- Click "Add Token" to generate new credentials
- Copy the
name,token, andsecretvalues
-
Configure GitHub Secrets:
- Go to your GitHub repository → Settings → Secrets and variables → Actions
- Add these repository secrets:
SHINYAPPS_ACCOUNT: Your shinyapps.io account nameSHINYAPPS_TOKEN: The token from shinyapps.ioSHINYAPPS_SECRET: The secret from shinyapps.io
-
Add new quizzes to automated deployment:
- Edit
config.Rand add your new quiz:
quiz_names <- c( "md-01-quiz", "md-02-quiz" # Add new quiz here )
- Edit
The GitHub Action (.github/workflows/deploy-quiz.yml):
- Triggers: On pushes to
main/devbranches or manual workflow dispatch - Environment: Sets up R 4.3.2 with required packages from DESCRIPTION
- Authentication: Uses repository secrets to authenticate with shinyapps.io
- Deployment: Executes
build.Rto deploy all applications defined there - Logging: Uploads deployment logs if any failures occur
For manual deployment, simply run the build script which handles everything automatically:
# Deploy all quizzes and landing page
source("build.R")The deployment system features:
- Automatic file bundling: CSV files and dependencies are automatically included
- Streamlined process: One script deploys everything configured in
config.R
The system now uses automatic configuration - adding a new quiz is simple:
Create modules/md-02-quiz.Rmd with the standardized YAML header:
---
title: "Module 2: Your Title"
output: learnr::tutorial
runtime: shiny_prerendered
description: "Your quiz description"
tutorial:
id: "module2-your-id"
---Add your quiz content following the existing pattern, including:
- GitHub username collection:
{r github-username, child='_github_username.Rmd'} - Quiz submission:
{r submission-section, child='_submission.Rmd'}
Edit config.R to include your new quiz:
quiz_names <- c(
"md-01-quiz",
"md-02-quiz" # Add new quiz here
)Run the build script to deploy everything:
source("build.R")This will:
- Automatically deploy the new quiz
- Update the landing page to show the new quiz
# Test a quiz locally
rmarkdown::run("modules/md-01-quiz.Rmd")# Test the landing page locally
shiny::runApp()Students access the system through:
- Landing page: Main hub showing all available quizzes
- Individual quizzes: Full learnr tutorials with interactive exercises, hints, and automatic grading
Each quiz runs independently and provides the complete learnr experience including progress tracking within that session.