create_question {shinyquiz} | R Documentation |
Create a quiz question
Description
Create a single quiz question. Used in conjunction with create_quiz()
to generate a quiz.
Usage
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 = ", ")
)
Arguments
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' |
Details
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')
.
Value
an object of class quizQuestion
an object of class quizQuestion
Functions
-
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.
Author(s)
Joseph Marlo, George Perrett
Joseph Marlo
See Also
add_choice()
, add_slider()
, add_numeric()
, add_text()
, create_question_raw()
Examples
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)