This Shiny app shows researchers how to keep code and data separated by putting paths in a config file instead of in the code. The same pattern makes eventual Azure deployment easier: point the config at wherever the data is mounted, no code edits required.
- The app reads
config/config.ymlvia theconfigpackage; you pick the environment withR_CONFIG_ACTIVE(default/development/production). - Each environment defines
data_diranddata_file; the app builds a CSV path from those values and loads it. - If the config package or file is missing, it falls back to
data/default_data.csv.
Current sample config (config/config.yml):
default:
data_dir: "data"
data_file: "default_data.csv"
development:
data_dir: "data"
data_file: "alternate_data.csv"
production:
data_dir: "/opt/data"
data_file: "prod_data.csv"-
Install
configif needed:install.packages("config"). -
Run from the project root:
R -e "shiny::runApp('app.R')" -
By default it uses the
defaultconfig (data/default_data.csv).
Switch environments with R_CONFIG_ACTIVE, e.g.:
R_CONFIG_ACTIVE=development R -e "shiny::runApp('app.R')"
R_CONFIG_ACTIVE=production R -e "shiny::runApp('app.R')"Edit config/config.yml to point to your own directories/files as needed.
- The resolved data source (path + which config/env was active).
- A data preview and simple summaries/plots to confirm you loaded the expected file.
- A Reload button to re-read
config/config.ymlafter edits.
- Keep code (the app) and data (CSV files) separate; mount or map your data location (Azure Files, Blob via fuse, or disk).
- Set
R_CONFIG_ACTIVE=productionin the Azure service and adjust theproductionblock inconfig/config.ymlto the mounted path/filename before deploying. - No code changes between local and cloud—only the config differs.
app.R– Shiny app; reads config, resolves the data path, and renders the UI.config/config.yml– environment-specific data locations.data/default_data.csvanddata/alternate_data.csv– sample datasets for local runs.
Keep data locations in configuration, not code. Swap configs (or environments) to move from local to Azure without touching the Shiny logic.