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.
Below are examples of each question type.
text
Use type = 'text'
to specify a text input type question.
```{r}
sd_question(
type = "text",
id = "word",
label = "Write a word:"
)
```
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
This widget only renders well in a Shiny environment, so we just show a screenshot here.
```{r}
sd_question(
type = 'slider',
id = 'climate_care',
label = "To what extent do you believe human-caused climate change is real?",
option = c(
"Don't Believe" = "dont_believe",
"Somewhat Believe" = "somewhat",
"Neutral" = "neutral",
"Believe" = "believe",
"Strongly Believe" = "strongly_believe"
)
)
```
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.
This widget only renders well in a Shiny environment, so we just show a screenshot here.
```{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.
This widget only renders well in a Shiny environment, so we just show a screenshot here.
```{r}
sd_question(
type = 'daterange',
id = 'hs_date',
label = "When did you start and finish high school?"
)
```
matrix
Use type = 'matrix'
to specify a matrix input type.
Disagree | Neutral | Agree | |
buy_gasoline | |||
buy_ev |
```{r}
sd_question(
type = "matrix",
id = "car_preference",
label = "Please indicate your agreement with the following statements.",
row = c(
"buy_gasoline" = "I'd like to buy a gasoline car.",
"buy_ev" = "I'd like to buy an EV."
),
option = c(
"Disagree" = "disagree",
"Neutral" = "neutral",
"Agree" = "agree"
)
)
```