Skip to content

About

Small example Shiny app showing how to use the config package and config file to separate data from code

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shiny Data Config Example

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.

How it works

  • The app reads config/config.yml via the config package; you pick the environment with R_CONFIG_ACTIVE (default/development/production).
  • Each environment defines data_dir and data_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"

Quick start (local)

  1. Install config if needed: install.packages("config").

  2. Run from the project root:

    R -e "shiny::runApp('app.R')"
  3. By default it uses the default config (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.

What the UI shows

  • 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.yml after edits.

Deploying to Azure (conceptual)

  • 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=production in the Azure service and adjust the production block in config/config.yml to the mounted path/filename before deploying.
  • No code changes between local and cloud—only the config differs.

Files of interest

  • app.R – Shiny app; reads config, resolves the data path, and renders the UI.
  • config/config.yml – environment-specific data locations.
  • data/default_data.csv and data/alternate_data.csv – sample datasets for local runs.

Key takeaway

Keep data locations in configuration, not code. Swap configs (or environments) to move from local to Azure without touching the Shiny logic.

About

Small example Shiny app showing how to use the config package and config file to separate data from code

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages