Formatting Questions

The sd_question() function has many optional arguments for modifying the appearance and behavior of questions. This page demonstrates some of the formatting options.

Markdown formatting

Markdown is supported for question labels and option labels.

Question labels

The label argument for any question type can accept markdown formatting. For example, the question below uses the * symbol to make some words bold, italic, and bold italic.

```{r}
sd_question(
  type   = 'mc',
  id     = 'markdown_label',
  label  = "**This** is a question *label* supporting ***markdown***:",
  option = c(
    "Option A" = "option_a",
    "Option B" = "option_b",
    "Option C" = "option_c"
  )
)
```

Option labels

Markdown formatting is also supported for the option labels in question types that have options, such as mc, mc_multiple, mc_buttons, and mc_multiple_buttons. For example:

```{r}
sd_question(
  type   = 'mc_buttons',
  id     = 'markdown_buttons',
  label  = "The 3 options below support markdown:",
  option = c(
    "*Option A*"     = "option_a",
    "**Option B**"   = "option_b",
    "***Option C***" = "option_c"
  )
)
```

HTML formatting

HTML formatting is supported for the option labels in question types that have options, such as mc_buttons and mc_multiple_buttons. This allows you to insert mixed content to achieve more complex labels, including plain text, markdown, and HTML code.

For example, here is a question with some complex labels for a choice question that include markdown and HTML code to embed images.

```{r}
# Define the option vector
html_button_options <- c("option_1", "option_2", "option_3")

# Define option labels that include markdown and HTML code to embed images
names(html_button_options) <- c(

  "**Option 1**<br>
   <img src='https://raw.githubusercontent.com/surveydown-dev/demo-conjoint-survey/main/images/fuji.jpg' width=100><br>
   **Type**: Fuji<br>
   **Price**: $ 2 / lb<br>
   **Freshness**: Average",

  "**Option 2**<br>
   <img src='https://raw.githubusercontent.com/surveydown-dev/demo-conjoint-survey/main/images/pinkLady.jpg' width=100><br>
    **Type**: Pink Lady<br>
    **Price**: $ 1.5 / lb<br>
    **Freshness**: Excellent",

  "**Option 3**<br>
    <img src='https://raw.githubusercontent.com/surveydown-dev/demo-conjoint-survey/main/images/honeycrisp.jpg' width=100><br>
    **Type**: Honeycrisp<br>
    **Price**: $ 2 / lb<br>
    **Freshness**: Poor"
)

sd_question(
  type   = 'mc_buttons',
  id     = 'html_buttons',
  label  = "A sample survey question using `mc_buttons`",
  option = html_button_options
)
```

Size formatting

Use the width, height arguments to change the size of the question.

For example, the question below uses the width and height arguments to change the size of a text area question.

```{r}
sd_question(
  type  = "textarea",
  id    = "change_width",
  label = "This text area has width set as 40% and height set as 100px:",
  width = "40%", 
  height = "100px"
)
```
Back to top