Add interactive quiz questions to a tutorial. Each quiz question is executed within a shiny runtime to provide more flexibility in the types of questions offered. There are three default types of quiz questions:
learnr_radioRadio button question. This question type will only allow for a single answer submission by the user. An answer must be marked for the user to submit their answer.
learnr_checkboxCheck box question. This question type will allow for one or more answers to be submitted by the user. At least one answer must be marked for the user to submit their answer.
learnr_textText box question. This question type will allow for free form text to be submitted by the user. At least one non-whitespace character must be added for the user to submit their answer.
quiz(..., caption = "Quiz")
question(
text,
...,
type = c("auto", "single", "multiple", "learnr_radio", "learnr_checkbox",
"learnr_text"),
correct = "Correct!",
incorrect = "Incorrect",
try_again = incorrect,
message = NULL,
post_message = NULL,
loading = c("**Loading:** ", text, "<br/><br/><br/>"),
submit_button = "Submit Answer",
try_again_button = "Try Again",
allow_retry = FALSE,
random_answer_order = FALSE,
options = list()
)
answer(text, correct = FALSE, message = NULL)One or more questions or answers
Optional quiz caption (defaults to "Quiz")
Question or option text
Type of quiz question. Typically this can be automatically determined
based on the provided answers. Pass "radio" to indicate that even though
multiple correct answers are specified that inputs which include only one correct
answer are still correct. Pass "checkbox" to force the use of checkboxes
(as opposed to radio buttons) even though only once correct answer was provided.
For question, text to print for a correct answer (defaults
to "Correct!"). For answer, a boolean indicating whether this answer is
correct.
Text to print for an incorrect answer (defaults to "Incorrect")
when allow_retry is FALSE.
Text to print for an incorrect answer (defaults to "Incorrect")
when allow_retry is TRUE.
Additional message to display along with correct/incorrect feedback. This message is always displayed after a question submission.
Additional message to display along with correct/incorrect feedback.
If allow_retry is TRUE, this message will only be displayed after the
correct submission. If allow_retry is FALSE, it will produce a second
message alongside the message message value.
Loading text to display as a placeholder while the question is loaded
Label for the submit button. Defaults to "Submit Answer"
Label for the try again button. Defaults to "Submit Answer"
Allow retry for incorrect answers. Defaults to FALSE.
Display answers in a random order.
Extra options to be stored in the question object.
Note, the print behavior has changed as the runtime is now Shiny based. If questions and quizes are printed in the console, the S3 structure and information will be displayed.
For more information and question type extension examples, please see the help documentation for question_methods and view the question_type tutorial: learnr::run_tutorial("question_type", "learnr").
quiz(
question("What number is the letter A in the alphabet?",
answer("8"),
answer("14"),
answer("1", correct = TRUE),
answer("23"),
incorrect = "See [here](https://en.wikipedia.org/wiki/English_alphabet) and try again.",
allow_retry = TRUE
),
question("Where are you right now? (select ALL that apply)",
answer("Planet Earth", correct = TRUE),
answer("Pluto"),
answer("At a computing device", correct = TRUE),
answer("In the Milky Way", correct = TRUE),
incorrect = paste0("Incorrect. You're on Earth, ",
"in the Milky Way, at a computer.")
)
)
#> Quiz: "Quiz"
#>
#> Question: "What number is the letter A in the alphabet?"
#> type: "learnr_radio"
#> allow_retry: TRUE
#> random_answer_order: FALSE
#> answers:
#> X: "8"
#> X: "14"
#> ✔: "1"
#> X: "23"
#> messages:
#> correct: "Correct!"
#> incorrect: "See <a href="https://en.wikipedia.org/wiki/English_alphabet">here</a> and try again."
#> try_again: "See <a href="https://en.wikipedia.org/wiki/English_alphabet">here</a> and try again."
#>
#> Question: "Where are you right now? (select ALL that apply)"
#> type: "learnr_checkbox"
#> allow_retry: FALSE
#> random_answer_order: FALSE
#> answers:
#> ✔: "Planet Earth"
#> X: "Pluto"
#> ✔: "At a computing device"
#> ✔: "In the Milky Way"
#> messages:
#> correct: "Correct!"
#> incorrect: "Incorrect. You're on Earth, in the Milky Way, at a computer."