```{r}
sd_question(
type = "text",
id = "word",
label = "Write a word:"
)
```
Question Types
All questions in a surveydown survey are created using the sd_question()
function. Calls to sd_question()
should be put inside code chunks in the survey.qmd
file to define the survey questions.
The function requires the following three arguments:
id
: A unique identifier for the question, which will be used as the variable name in the resulting survey data.label
: The label that will be displayed on the question in the survey.type
: The type of question.
Many question types also require an option
argument, which is a named vector of options for the question (e.g. for multiple choice questions). The function also includes many other optional arguments that can be used to customize the question appearance and behavior. See the package documentation for more details.
The following question types are currently supported:
text
: Single line open text input.textarea
: Multiple line open text input.numeric
: Single line numeric text input.mc
: Multiple choice with a single select option (radio buttons).mc_buttons
: Same asmc
but as a “button” style instead of radio buttons.mc_multiple
: Multiple choice with mutliple select options (check boxes).mc_multiple_buttons
: Same asmc_multiple
but as a “button” style instead of check boxes.select
: Select a choice from a drop down menu.slider
: (Under construction) Slider to select discrete categories or continuous numbers.date
: Select a date from a calendar widget.daterange
: Select two dates from calendar widgets (e.g. begin and end dates).
Below are examples of each question type.
text
Use type = 'text'
to specify a text input type question.
textarea
Use type = 'textarea'
to specify a text area input type question.
```{r}
sd_question(
type = "textarea",
id = "paragraph",
label = "Write a paragraph:"
)
```
numeric
Use type = 'numeric'
to specify a numeric input type.
```{r}
sd_question(
type = 'numeric',
id = 'age',
label = "What's your age?"
)
```
mc
Use type = 'mc'
to specify a multiple choice type question with a single choice option.
```{r}
sd_question(
type = 'mc',
id = 'artist',
label = "Which artist do you prefer most from this list?",
option = c(
"Taylor Swift" = "taylor_swift",
"Beyoncé" = "beyonce",
"Adele" = "adele",
"Rihanna" = "rihanna",
"Lady Gaga" = "ladygaga",
"Ed Sheeran" = "ed_sheeran",
"Drake" = "drake"
)
)
```
mc_multiple
Use type = 'mc_multiple'
to specify a multiple choice type question with multiple selection enabled.
```{r}
sd_question(
type = 'mc_multiple',
id = 'swift',
label = "What are your favorite Taylor Swift albums (select all that apply)?",
option = c(
"Taylor Swift (2006)" = "taylor_swift",
"Fearless (2008)" = "fearless",
"Speak Now (2010)" = "speak_now",
"Red (2012)" = "red",
"1989 (2014)" = "1989",
"Reputation (2017)" = "reputation",
"Lover (2019)" = "lover",
"Folklore (2020)" = "folklore",
"Evermore (2020)" = "evermore",
"Midnights (2022)" = "midnights"
)
)
```
select
Use type = 'select'
to specify a drop down select type question.
```{r}
sd_question(
type = 'select',
id = 'education',
label = "What is the highest level of education you have attained?",
option = c(
"Did not attend high school" = "hs_no",
"Some high school" = "hs_some",
"High school graduate" = "hs_grad",
"Some college" = "college_some",
"College" = "college_grad",
"Graduate Work" = "grad",
"Prefer not to say" = "no_response"
)
)
```
slider
Due to compatibility issues, the slider
type is still under construction.
date
Use type = 'date'
to specify a date input type. The date value will be today’s date by default. Upon clicking on the text box, you are provided with a date dialog box to choose date from.
The dialog box will only appear in a Shiny environment, hence why it is not appearing when clicked in this example.
```{r}
sd_question(
type = 'date',
id = 'dob',
label = "What is your date of birth?"
)
```
daterange
Use type = 'daterange'
to specify a date range input type.
The dialog box will only appear in a Shiny environment, hence why it is not appearing when clicked in this example.
```{r}
sd_question(
type = 'daterange',
id = 'hs_date',
label = "When did you start and finish high school?"
)
```