Render a question which asks the user to input a value. Questions of numeric support auto-grading.
text_question(
title,
points = 1,
type = c("textarea", "text", "numeric"),
width = "100%",
height = NULL,
placeholder = NULL,
solution = NULL,
solution_quoted = FALSE,
comp = comp_digits(3, 1),
label = "Type your answer below.",
hide_label = FALSE,
mandatory = FALSE,
id = NULL,
title_container = h6,
static_title = NULL,
mathjax_dollar
)
comp_abs(tol)
comp_rel(tol)
comp_digits(digits, pm = 1)
question title. Markdown is supported and by default the title will be rendered dynamically if it contains inline R code.
total number of points for the question. Set to NULL
to not give any points for the question.
Will be shown next to the question text, formatted using the points_format
given in exam_config()
.
can be one of textarea
(default), text
or numeric
.
the width of the input, e.g., '300px' or '100%'; see shiny::validateCssUnit()
.
the height of the input, e.g., '300px' or '100%'; see shiny::validateCssUnit()
. Only relevant for
type="textarea"
.
A character string giving the user a hint as to what can be entered into the control. Internet Explorer 8 and 9 do not support this option.
an expression to compute the solution to the answer.
The expression is evaluated in the environment returned by the data provider set up via exam_config()
.
See below for details on how to auto-grade questions of type numeric.
is the solution
expression quoted?
function comparing the user's input with the correct answer. Must be a function taking two
named arguments: input
(the user's input value) and answer
(the correct answer).
a label to help screen readers describe the purpose of the input element.
hide the label from non-screen readers.
is this question mandatory for submitting the section? If TRUE
, a user can only navigate to the
next section if the question is answered.
question identifier to be used instead of the code chunk label. Must only contain
characters a-z
, A-Z
, 0-9
, dash (-
), or underscore (_
).
a function to generate an HTML element to contain the question title.
if NULL
, the title will be rendered statically if it doesn't contain inline R code, otherwise
it will be rendered dynamically. If TRUE
, always render the title statically. If FALSE
, always render the
title dynamically on the server.
absolute tolerance (for comp_abs()
) or relative tolerance (for comp_rel()
).
number of digits relevant for comparison (significant digits if the correct answer is less than 1 in absolute value).
amount by how much the last (significant) digit may vary between the user's input and the correct answer.
The solution is computed by evaluating the expression given in solution
in the rendering environment.
The expression must yield either a single character string or, if the question is of type numeric, a numeric value.
The result of the expression is rendered with commonmark.
To auto-grade numeric questions, the solution
expression can yield a numeric value or a character value with
attribute answer
. This number is compared against the user's answer using the function provided via comp
.
comp_abs()
: compare the user input and the correct answer in absolute terms
(returns abs(input - answer) < tol
).
comp_rel()
: compare the user input and the correct answer in relative terms
(returns abs(input / answer - 1) < tol
).
comp_digits()
: allow the last digit vary by +/- pm
. For answers greater than 1 (in absolute value),
digits
is the number of digits after the decimal point and an absolute tolerance of
of tol = pm * 10^-digits
is used.
For answers less than 1, digits
is the number of significant digits and an
absolute tolerance of tol = pm * 10^(-shift)
is used (shift
is taken such that
the last sign. digit can vary by +/- pm
). Returns abs(input - answer) < tol
).
Other exam question types:
mc_question()