sd_question {surveydown} | R Documentation |
Create a survey question
Description
This function creates various types of survey questions for use in a Surveydown survey.
Usage
sd_question(
id,
type = NULL,
label = NULL,
option = NULL,
cols = "80",
direction = "horizontal",
status = "default",
width = "100%",
height = NULL,
selected = NULL,
label_select = "Choose an option...",
grid = TRUE,
individual = TRUE,
justified = FALSE,
force_edges = TRUE,
placeholder = NULL,
resize = NULL,
row = NULL,
default = NULL,
yml = "questions.yml",
...
)
Arguments
id |
A unique identifier for the question, which will be used as the variable name in the resulting survey data. |
type |
Specifies the type of question. Possible values are |
label |
Character string. The label for the UI element, which can be
formatted with markdown. Defaults to |
option |
Named vector for the |
cols |
Integer. Number of columns for the |
direction |
Character string. The direction for button groups
( |
status |
Character string. The status for button groups.
Defaults to |
width |
Character string. The width of the UI element.
Defaults to |
height |
Character string. The height of the input for the
|
selected |
Value. The selected value(s) for certain input elements. |
label_select |
Character string. The label for the select input.
Defaults to |
grid |
Logical. Whether to show a grid for slider input.
Defaults to |
individual |
Logical. Whether buttons in a group should be individually
styled. Defaults to |
justified |
Logical. Whether buttons in a group should fill the width
of the parent div. Defaults to |
force_edges |
Logical. Whether to force edges for slider input.
Defaults to |
placeholder |
Character string. Placeholder text for |
resize |
Character string. Resize option for textarea input.
Defaults to |
row |
List. Used for |
default |
Numeric, length 1 (for a single sided slider), or 2 for a two sided (range based) slider. Values to be used as the starting default for the slider. Defaults to the median of values. |
yml |
Character string. The name of the YAML file to load question configurations from.
Defaults to |
... |
Additional arguments, often specific to different input types.
Examples include |
Details
The function supports various question types:
-
"select"
: A dropdown selection -
"mc"
: Multiple choice (single selection) -
"mc_multiple"
: Multiple choice (multiple selections allowed) -
"mc_buttons"
: Multiple choice with button-style options (single selection) -
"mc_multiple_buttons"
: Multiple choice with button-style options (multiple selections allowed) -
"text"
: Single-line text question -
"textarea"
: Multi-line text question -
"numeric"
: Numeric question -
"slider"
: Slider question -
"slider_numeric"
: Extended numeric slider question -
"date"
: Date question -
"daterange"
: Date range question -
"matrix"
: Matrix-style question with rows and columns
For "matrix"
type questions, use the row
parameter to define the rows of
the matrix. Each element in the row
list should have a name (used as the
row ID) and a value (used as the row label).
Value
A 'shiny' UI element wrapped in a div with a data attribute for question ID.
Examples
if (interactive()) {
library(surveydown)
# Get path to example survey file
survey_path <- system.file("examples", "basic_survey.qmd",
package = "surveydown")
# Copy to a temporary directory
temp_dir <- tempdir()
file.copy(survey_path, file.path(temp_dir, "survey.qmd"))
orig_dir <- getwd()
setwd(temp_dir)
# Define a minimal server
server <- function(input, output, session) {
sd_server()
}
# Run the app
shiny::shinyApp(ui = sd_ui(), server = server)
# Clean up
setwd(orig_dir)
}