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:

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"
  )
)
```

mc_buttons

Use type = 'mc_buttons' to generate the button version of mc.


*
```{r}
sd_question(
  type   = 'mc_buttons',
  id     = 'fruit',
  label  = "Which fruit do you prefer most from this list?",
  option = c(
    "Apple"      = "apple",
    "Banana"     = "banana",
    "Pear"       = "pear",
    "Strawberry" = "strawberry",
    "Grape"      = "grape",
    "Mango"      = "mango",
    "Watermelon" = "watermelon"
  )
)
```

Use direction = "vertical" to display the button options vertically.


*
```{r}
sd_question(
  type   = 'mc_buttons',
  id     = 'fruit',
  label  = "Which fruit do you prefer most from this list?",
  option = c(
    "Apple"      = "apple",
    "Banana"     = "banana",
    "Pear"       = "pear",
    "Strawberry" = "strawberry",
    "Grape"      = "grape",
    "Mango"      = "mango",
    "Watermelon" = "watermelon"
  ), 
  direction = "vertical"
)
```

mc_multiple_buttons

Use type = 'mc_multiple_buttons' to generate the button version of mc_multiple.


*
```{r}
sd_question(
  type  = 'mc_multiple_buttons',
  id    = 'michael_jackson',
  label = "Which are your favorite Michael Jackson songs (select all that apply)?",
  option = c(
    "Thriller (1982)"          = "thriller",
    "Billie Jean (1982)"       = "billie_jean",
    "Beat It (1982)"           = "beat_it",
    "Man in the Mirror (1987)" = "man_in_the_mirror",
    "Smooth Criminal (1987)"   = "smooth_criminal",
    "Black or White (1991)"    = "black_or_white",
    "Bad (1987)"               = "bad",
    "Human Nature (1982)"      = "human_nature"
  )
)
```

Use direction = "vertical" to display the button options vertically.


*
```{r}
sd_question(
  type  = 'mc_multiple_buttons',
  id    = 'michael_jackson',
  label = "Which are your favorite Michael Jackson songs (select all that apply)?",
  option = c(
    "Thriller (1982)"          = "thriller",
    "Billie Jean (1982)"       = "billie_jean",
    "Beat It (1982)"           = "beat_it",
    "Man in the Mirror (1987)" = "man_in_the_mirror",
    "Smooth Criminal (1987)"   = "smooth_criminal",
    "Black or White (1991)"    = "black_or_white",
    "Bad (1987)"               = "bad",
    "Human Nature (1982)"      = "human_nature"
  ), 
  direction = "vertical"
)
```

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

Note

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.

Note

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.

Note

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"
  )
)
```
Back to top