Skip to contents

Setup the global survey environment by creating database connections, environment variables, and a future asynchronous processing plan. The function:

  • Validates database configuration parameters

  • Sets required environment variables if not already present

  • Configures optional Shiny settings

  • Establishes a global database connection pool

  • Sets up asynchronous processing using future package with OS-specific configuration

Usage

survey_setup(db_config, shiny_config = NULL, workers = 2L)

Arguments

db_config

A list containing database configuration parameters:

  • host: Database host address

  • port: Database port number

  • db_name: Name of the database

  • user: Database username

  • password: Database password

  • write_table: Name of the table for write operations

shiny_config

Optional list of Shiny configuration parameters to be passed to configure_shiny function. If provided, these settings will be applied before database initialization.

workers

Number of workers for parallel processing. Default is 3.

Value

Invisibly returns the database pool object. The pool is also assigned to 'app_pool' in the global environment.

Invisibly returns the initialized database pool object

Details

The function performs several initialization steps:

  • Validates the write_table parameter is a non-empty string

  • Checks for required database configuration fields

  • Sets environment variables (HOST, PORT, DB_NAME, USER, PASSWORD) if not present

  • Applies optional Shiny configuration

  • Creates a global database connection pool if it doesn't exist

  • Initializes future package for asynchronous operations based on OS

Environment variables are only set if they don't already exist, preserving any existing configurations.

Database Pool

The database pool is created using the db_pool_open function and stored in the global environment as 'app_pool'. If a pool already exists, it is not recreated.

Asynchronous Processing

The function detects the operating system and sets up the appropriate future plan:

  • Windows: Uses multisession

  • macOS: Uses multicore if supported, falls back to multisession

  • Linux: Uses multicore if supported, falls back to multisession