10:00
10:00
Each demo-* folder is a complete survey.
Open one in Positron with File › Open Folder…
survey.qmd
A Quarto doc defining the main survey content (pages, text, images, questions, etc).
app.R
An R script defining the survey Shiny app. It sets up the database and server, and launches the survey.
---
survey-settings:
mode: preview
---
```{r}
library(surveydown)
```
--- welcome
# Welcome to our survey!
```{r}
sd_question(
type = "mc",
id = "penguins",
label = "What's your favorite penguin?",
option = c(
"Adélie" = "adelie",
"Chinstrap" = "chinstrap",
"Gentoo" = "gentoo"
)
)
```
--- end
This is the last page of the survey.
```{r}
sd_close()
```---
survey-settings:
mode: preview
---
```{r}
library(surveydown)
```
--- welcome
# Welcome to our survey!
```{r}
sd_question(
type = "mc",
id = "penguins",
label = "What's your favorite penguin?",
option = c(
"Adélie" = "adelie",
"Chinstrap" = "chinstrap",
"Gentoo" = "gentoo"
)
)
```
--- end
This is the last page of the survey.
```{r}
sd_close()
```YAML header (survey settings)
mode: preview saves responses to a local file while you build
Load surveydown package
---
survey-settings:
mode: preview
---
```{r}
library(surveydown)
```
--- welcome
# Welcome to our survey!
```{r}
sd_question(
type = "mc",
id = "penguins",
label = "What's your favorite penguin?",
option = c(
"Adélie" = "adelie",
"Chinstrap" = "chinstrap",
"Gentoo" = "gentoo"
)
)
```
--- end
This is the last page of the survey.
```{r}
sd_close()
```---
survey-settings:
mode: preview
---
```{r}
library(surveydown)
```
--- welcome
# Welcome to our survey!
```{r}
sd_question(
type = "mc",
id = "penguins",
label = "What's your favorite penguin?",
option = c(
"Adélie" = "adelie",
"Chinstrap" = "chinstrap",
"Gentoo" = "gentoo"
)
)
```
--- end
This is the last page of the survey.
```{r}
sd_close()
```
Use markdown for page content
Use sd_question() in a code chunk for survey questions
A Next button is added to every page automatically
---
survey-settings:
mode: preview
---
```{r}
library(surveydown)
```
--- welcome
# Welcome to our survey!
```{r}
sd_question(
type = "mc",
id = "penguins",
label = "What's your favorite penguin?",
option = c(
"Adélie" = "adelie",
"Chinstrap" = "chinstrap",
"Gentoo" = "gentoo"
)
)
```
--- end
This is the last page of the survey.
```{r}
sd_close()
```
Use sd_close() on the last page for an “Exit Survey” button
05:00
Step 1: Open the demo-question-types folder in Positron
(File › Open Folder…)
Step 2: Open app.R and click the “Run App” arrow in the top-left (near where the “preview” button usually is for Quarto docs)
Step 3: Click through the survey, then look at survey.qmd to see how each question was made
In the R console, run:
Optional: Specify a path and / or a template:
Warning
Every surveydown survey should be in its own separate project folder.
All survey settings go in the YAML header at the top of survey.qmd
No header at all? Everything uses the defaults.
Full list of settings on the Survey Settings docs page
modeSet under survey-settings in the YAML header:
mode |
Where responses are saved |
|---|---|
preview |
preview_data.csv in your survey folder |
local |
local_data.csv in your survey folder |
database (default) |
Your database (see part 4) |
Use preview while you build, switch to database before you launch
Pick a different bootswatch theme with the theme key:
Make a custom theme with a custom.scss file:
Modify the survey progress bar with the barcolor and barposition keys:
Start each page with --- and a page id:
Next buttons are added automatically.
Add a Previous button to every page in the YAML:
Insert questions using the sd_question() function, like this:
Some common types you may want to use:
| Type | Description |
|---|---|
mc |
Multiple choice question (single choice) |
mc_multiple |
Multiple choice question (multiple choices) |
mc_buttons |
Multiple choice question (large buttons) |
select |
Drop down menu (choose one) |
text |
Open text, single row |
textarea |
Open text, block |
numeric |
Numbers only |
matrix |
Several questions with the same options (e.g. agree / disagree) |
questions.yml fileI recommend just writing html code, like this
sdstudio::launch()10:00
surveydown::sd_create_survey() and open its folder in Positron.survey.qmd. Include the following:
All go in the server() function in app.R:
| Function | What it does |
|---|---|
sd_show_if() |
Show a question or page if a condition is TRUE |
sd_skip_if() |
Skip forward to a page if a condition is TRUE |
sd_stop_if() |
Stop navigation (with a message) if a condition is TRUE |
Define both conditional and target questions in survey.qmd
# Conditional question
sd_question(
type = "mc",
id = "penguins",
label = "Which is your favorite type of penguin?",
option = c(
"Adélie" = "adelie",
"Chinstrap" = "chinstrap",
"Gentoo" = "gentoo",
"Other" = "other"
)
)
# Target question
sd_question(
type = "text",
id = "penguins_other",
label = "Please specify the other penguin type:"
)Define condition with sd_show_if() in app.R
sd_value("id") to get the value of a question
First, define all pages in your survey.qmd file:
In app.R:
sd_store_value() saves rand_val in your response data, so you know which version each respondent saw
In survey.qmd: Target screenout question
In app.R:
See the demo-conditional-showing anddemo-conditional-skipping folders
15:00
05:00
Steps to connect a database via Supabase:
Click the “connect” button in your project
Choose “Direct”, then find the “Transaction pooler” section
sd_db_connect() uses the .env file to make the database connection.
Then set mode: database in survey.qmd
(or delete the mode line — it’s the default)
sdstudio::launch() to locally view data
10:00
surveydown::sd_db_config() in your console to store your Supabase credentials.mode: preview to mode: database in your survey.qmd.sdstudio::launch()
sd_output() to display question valuessd_output()Question in survey.qmd:
sd_output()Question in survey.qmd:
07:00
In your survey, display a question value somewhere with:
In your survey, display a question option label somewhere with: