create_question | R Documentation |
Create a single quiz question. Used in conjunction with create_quiz()
to generate a quiz.
create_question(
prompt,
...,
type = c("auto", "single", "multiple"),
input = c("auto", "select", "checkbox"),
shuffle = FALSE,
ns = shiny::NS("quiz")
)
create_question_raw(
prompt,
grader,
correct_answer_pretty,
user_answer_prettifier = function(user_input) paste0(user_input, collapse = ", ")
)
prompt |
Text of the question prompt. Can also be an HTML element such as |
... |
Objects of class 'quizChoice' generated from |
type |
One of c('auto', 'single', 'multiple'). Can the user select only one answer or multiple? |
input |
One of c('auto', 'select', 'checkbox'). Should the UI for a select object created by |
shuffle |
TRUE or FALSE. If TRUE order of choices will be randomly shuffled. |
ns |
Namespace function generated from |
grader |
A function that takes the user answer and determines if it is correct. Must take one argument and return TRUE or FALSE. This is wrapped with |
correct_answer_pretty |
A string representing the correct answer that is printed 'pretty' |
user_answer_prettifier |
A function with one argument that takes the user's answers and prints it 'pretty' |
create_question
is the default method of creating quiz questions.
create_question_raw()
allows any HTML in the prompt
. This must contain a shiny input that is accessible via input$answers
. The namespace also needs care. The default inputId
is shiny::NS('quiz')('answers')
.
an object of class quizQuestion
an object of class quizQuestion
create_question()
: Create a quiz question
create_question_raw()
: Create a quiz question using custom inputs. This is a more flexible function that allows any html.
Joseph Marlo, George Perrett
Joseph Marlo
add_choice()
, add_slider()
, add_numeric()
, add_text()
, create_question_raw()
q <- create_question(
prompt = 'My prompt explaining what the ATE of this thing should be',
add_choice("34"),
add_choice("59", TRUE),
add_choice("98", TRUE)
)
q2 <- create_question(
prompt = 'My prompt explaining what the ATC of this thing should be',
add_slider(0, 30, 15, correct = 10)
)
quiz <- create_quiz(q, q2)
q3 <- create_question_raw(
prompt = htmltools::div(
htmltools::p("my question"),
shiny::selectInput(
inputId = shiny::NS('quiz')('answers'),
label = 'Select 5',
choices = c(4, 5, 6)
)
),
grader = \(user_input) user_input == '5',
correct_answer_pretty = '5'
)
quiz2 <- create_quiz(q3, q2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.