Add interactive drop-down tasks to your learnr
tutorials.
An alternative option to question_radio
when you have a lot of options
and want to save space.
Usage
question_dropdown(
text,
...,
type = "dropdown",
correct = "Correct!",
incorrect = "Incorrect",
try_again = incorrect,
allow_retry = FALSE,
random_answer_order = FALSE,
options = sortable::sortable_options()
)
Arguments
- text
Question or option text
- ...
parameters passed onto learnr answer.
- type
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 one correct answer was provided.- correct
For
question
, text to print for a correct answer (defaults to "Correct!"). Foranswer
, a boolean indicating whether this answer is correct.- incorrect
Text to print for an incorrect answer (defaults to "Incorrect") when
allow_retry
isFALSE
.- try_again
Text to print for an incorrect answer when
allow_retry
isTRUE
. Defaults to "Incorrect. Be sure to select every correct answer." for checkbox questions and "Incorrect" for non-checkbox questions.- allow_retry
Allow retry for incorrect answers. Defaults to
FALSE
.- random_answer_order
Display answers in a random order.
- options
Extra options to be stored in the question object. This is useful when using custom question types. See
sortable::question_rank()
for an example question implementation that uses theoptions
parameter.
Examples
question_dropdown(
"Pick the letter B",
learnr::answer("A"),
learnr::answer("B", correct = TRUE),
learnr::answer("C"),
learnr::answer("D"),
allow_retry = TRUE,
random_answer_order = TRUE
)
#> Question: "Pick the letter B"
#> type: "dropdown"
#> allow_retry: TRUE
#> random_answer_order: TRUE
#> answers:
#> X: "A"
#> ✔: "B"
#> X: "C"
#> X: "D"
#> messages:
#> correct: "Correct!"
#> incorrect: "Incorrect"
#> try_again: "Incorrect"