Skip to contents

The following function was modified from the sortable package, available at https://github.com/rstudio/sortable and a solution thread by "stefan's on Jun 01, 2022". Many thanks to the sortable author who developed tools to drag and drop objects in rank order. This extends the "question_rank" option so that you can drag any option from the word bank into the answer blanks.

Usage

question_wordbank(
  text,
  ...,
  choices,
  wordbank = NULL,
  box = 6,
  arrange = "random",
  type = "wordbank",
  correct = "Correct!",
  incorrect = "Incorrect",
  loading = c("**Loading:** ", text, "<br/><br/><br/>"),
  submit_button = "Submit Answer",
  try_again_button = "Try Again",
  allow_retry = FALSE,
  random_answer_order = TRUE,
  options = sortable::sortable_options()
)

Arguments

text

Question or option text

...

parameters passed onto learnr answer.

choices

a vector of choices that will remain stationary in the left column.

wordbank

a vector of choices to be placed into the blanks when providing more options than answers. If NULL then the wordbank will be set equal to the answer choices.

box

a number between 1 and 11, inclusive, indicating the width of the 'choices' box. The default is 6 which corresponds to 50% of the page width.

arrange

either 'random', 'ordered' or 'none'; default is random. Set equal to ordered if you want the wordbank list to appear alphabetically. Set equal to none for the wordbank to appear exactly as provided.

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!"). For answer, a boolean indicating whether this answer is correct.

incorrect

Text to print for an incorrect answer (defaults to "Incorrect") when allow_retry is FALSE.

loading

Loading text to display as a placeholder while the question is loaded. If not provided, generic "Loading..." or placeholder elements will be displayed.

submit_button

Label for the submit button. Defaults to "Submit Answer"

try_again_button

Label for the try again button. Defaults to "Submit Answer"

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 the options parameter.

Value

A custom learnr question, with type = wordbank.

Details

Add interactive word bank tasks to your learnr tutorials. The student can drag-and-drop the answer options from the word bank to match the corresponding options.

The choices should be a set of options that the word bank choices will match to. The choices should be of equal length to the answers.

The answer should contain the set of solutions that match the choices. The first answer much match the first choice and so forth.

The word bank should be a set of options for the user to choose from to drag and drop into the blanks. If can be shorter or longer than then number of blanks but must include all unique answer options. If no word bank is provided it will be set equal to the answer options.

Examples

question_wordbank(
  "Drag the numbers to match the corresponding letter's position in the alphabet.",
  choices = c("C", "B", "A", "D"),
  learnr::answer(c("3", "2", "1", "4"), correct = TRUE),
  allow_retry = TRUE
)
#> Question: "Drag the numbers to match the corresponding letter’s position in the alphabet."
#>   type: "wordbank"
#>   allow_retry: TRUE
#>   random_answer_order: TRUE
#>   answers:
#>     ✔: "3
#> 2
#> 1
#> 4"
#>   messages:
#>     correct: "Correct!"
#>     incorrect: "Incorrect"
#>     try_again: "Incorrect"