This function creates various types of survey questions for use in a Surveydown survey.
Usage
sd_question(
type,
id,
label,
cols = "80",
direction = "horizontal",
status = "default",
width = "100%",
height = "100px",
selected = NULL,
label_select = "Choose an option...",
grid = TRUE,
individual = TRUE,
justified = FALSE,
force_edges = TRUE,
option = NULL,
placeholder = NULL,
resize = NULL
)
Arguments
- type
Specifies the type of question. Possible values are "select", "mc", "mc_multiple", "mc_buttons", "mc_multiple_buttons", "text", "textarea", "numeric", "slider", "date", and "daterange".
- id
A unique identifier for the question, which will be used as the variable name in the resulting survey data.
- label
Character string. The label for the UI element, which can be formatted with markdown.
- cols
Integer. Number of columns for the textarea input. Defaults to 80.
- direction
Character string. The direction for button groups ("horizontal" or "vertical"). Defaults to "horizontal".
- status
Character string. The status for button groups. Defaults to "default".
- width
Character string. The width of the UI element. Defaults to "100%".
- height
Character string. The height of the textarea input. Defaults to "100px".
- selected
Value. The selected value(s) for certain input elements.
- label_select
Character string. The label for the select input. Defaults to "Choose an option...".
- grid
Logical. Whether to show a grid for slider input. Defaults to TRUE.
- individual
Logical. Whether buttons in a group should be individually styled. Defaults to TRUE.
- justified
Logical. Whether buttons in a group should be justified. Defaults to FALSE.
- force_edges
Logical. Whether to force edges for slider input. Defaults to TRUE.
- option
List. Options for the select, radio, checkbox, and slider inputs.
- placeholder
Character string. Placeholder text for text and textarea inputs.
- resize
Character string. Resize option for textarea input. Defaults to NULL.
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 input
"textarea": Multi-line text input
"numeric": Numeric input
"slider": Slider input
"date": Date input
"daterange": Date range input
Examples
sd_question("text", "name", "What is your name?")
#> <div id="container- name" data-question-id="name" class="question-container" oninput="Shiny.setInputValue('name_interacted', true, {priority: 'event'});">
#> <div class="form-group shiny-input-container" style="width:100%;">
#> <label class="control-label" id="name-label" for="name"><p>What is your name? <span class='required-asterisk' style='display:none; color: red; font-size: 1.5em; vertical-align: middle; position: relative; top: 0.1em;'>*</span></p>
#> </label>
#> <input id="name" type="text" class="shiny-input-text form-control" value=""/>
#> </div>
#> </div>
sd_question("mc", "color", "What is your favorite color?", option = c("Red", "Blue", "Green"))
#> <div id="container- color" data-question-id="color" class="question-container" oninput="Shiny.setInputValue('color_interacted', true, {priority: 'event'});">
#> <div id="color" style="width:100%;" class="form-group shiny-input-radiogroup shiny-input-container" role="radiogroup" aria-labelledby="color-label">
#> <label class="control-label" id="color-label" for="color"><p>What is your favorite color? <span class='required-asterisk' style='display:none; color: red; font-size: 1.5em; vertical-align: middle; position: relative; top: 0.1em;'>*</span></p>
#> </label>
#> <div class="shiny-options-group">
#> <div class="radio">
#> <label>
#> <input type="radio" name="color" value="Red"/>
#> <span>Red</span>
#> </label>
#> </div>
#> <div class="radio">
#> <label>
#> <input type="radio" name="color" value="Blue"/>
#> <span>Blue</span>
#> </label>
#> </div>
#> <div class="radio">
#> <label>
#> <input type="radio" name="color" value="Green"/>
#> <span>Green</span>
#> </label>
#> </div>
#> </div>
#> </div>
#> </div>