Server Options

All survey configuration settings are defined within the server function in the app.R file. The server() function is a standard Shiny server function that takes input, output, and session as arguments.

If you create a new survey using a template, the server() function looks like this:

server <- function(input, output, session) {

  # Define conditional skip logic (skip to page if a condition is true)
  sd_skip_if()

  # Define conditional display logic (show a question if a condition is true)
  sd_show_if()

  # Main server to control the app
  sd_server(db = db)

}

The sd_skip_if() and sd_show_if() functions are used to define conditional skip and show logic for the survey (see the Conditional Control page for more details).

The sd_server() function is used to run the survey. It handles the main logic, such as page navigation and managing the survey data. The db = db argument is required if you are using a database connection, which should be defined using the sd_database() function (see the Store Data page for more details).

The sd_server() function also has many other optional arguments that can be used to customize the survey behavior. This page details these options.

Required questions

By default, no questions are required. However, you can make questions required by providing a vector containing the id of the questions to be required to the required_questions argument in sd_server(), like

sd_server(
  required_questions = c("vehicle_ownership", "penguins_other")
)
1
The required_questions argument takes a vector of question ids that you want to make required.

This will make the respondent unable to proceed until they have answered the required questions. It will also place a red asterisk (*) next to the question label to indicate that the question is required.

You can also make all questions required by setting all_questions_required = TRUE like this:

sd_server(
  all_questions_required = TRUE
)

Starting page

When editing your survey, it can be helpful to start the survey at a specific page. You can define the starting page with the start_page argument in the sd_server() function, like this:

sd_server(
  start_page = "page_id"
)

Auto scroll

The auto scroll feature allows the page to automatically scroll according to the user’s working progress and is enabled by default.

sd_server(
  auto_scroll = TRUE # Change to FALSE to switch it off.
)

Rating question

You may want to add a rating question by the end of the survey to collect user reflections. Simply set rate_survey to TRUE (Default to FALSE):

sd_server(
  rate_survey = TRUE
)

Survey rating is triggered by the “Exit Survey” button by the end of the survey. If you want to implement the survey rating, make sure you define the Exit Button by the end of the survey using the sd_close() function, and then define rate_survey = TRUE in sd_server().

Below are the TRUE and FALSE cases for rate_survey:

If rate_survey is TRUE, a survey rating question will pop up:

If rate_survey is FALSE, a confirm exit dialog box will pop up:

System translations

To systematically display the preset system messages and button text elements in a different language, change the system language using a different country code (default is "en" for English).

For example, to use Spanish use:

sd_server(
  language = "es"
)

Five languages are supported by default, but you can customize the messages to any language (or any message) you want. See the System Translations page for more details.

Cookies

Cookies are used to store user sessions, including their session ID, survey data storage (backend), and their survey progress (frontend).

By default, the cookies are enabled. You can disable the cookies by setting cookies = FALSE in the sd_server() function, like this:

sd_server(
  cookies = FALSE
)
Back to top