Interactive Shiny app that queries Colorado’s open-data Socrata SODA v2 endpoint
(/resource/<VIEW_ID>.json using $query) and shows descriptive stats by date/group.
- Default dataset:
a498-a63g(you can swap the view id anytime).
Note: this demo view doesn’t have a true date column; the time-series will be blank until you use a dataset with dates.
- R (≥ 4.2)
- Internet access to
https://data.colorado.gov - (Recommended) a Socrata App Token
# first time
git clone https://github.com/ileleiwi/co-shiny-socrata.git
cd co-shiny-socrata
# later, to update
git pullR -q -e "source('install.R')"Create a token at https://data.colorado.gov/profile/edit/developer_settings, then set it as an environment variable:
macOS / Linux (bash/zsh)
export SOCRATA_APP_TOKEN="your_token_here"Windows PowerShell
$env:SOCRATA_APP_TOKEN = "your_token_here"R (temporary for this session)
Sys.setenv(SOCRATA_APP_TOKEN = "your_token_here")The app reads the token from
config.yml→app_token_env(defaults toSOCRATA_APP_TOKEN).
The sidebar will show “Token detected ✓” when it’s available.
R -q -e "shiny::runApp(port=8080, host='127.0.0.1', launch.browser=TRUE)"If your browser doesn’t open automatically, visit: http://localhost:8080
- Click Health check → should report row/column counts.
- In the SoQL box, start with:
SELECT * LIMIT 100
- Click Fetch.
- In Pickers:
- Choose a Group column (e.g.,
race_ethnicity). - Choose a Numeric column (e.g.,
median_household_income). - (Optional) Choose a Date column + range if your dataset has dates.
- Choose a Group column (e.g.,
- Explore:
- Time series (sum per date; requires a date column).
- Grouped stats bar chart (Sum / Mean / Median / Count).
- Grouped summary table and Raw data (both downloadable as CSV).
Two ways:
- Quick (UI only): Replace Socrata View ID in the sidebar (e.g.,
abcd-1234) and adjust your SoQL. - Config (persisted): Edit
config.yml:socrata_domain: data.colorado.gov view_id: a498-a63g app_token_env: SOCRATA_APP_TOKEN
Tip: Use SoQL for server-side aggregation, e.g.:
SELECT date_trunc_ymd(date_col) AS day, group_col, SUM(value_col) AS n GROUP BY day, group_col ORDER BY day LIMIT 50000
- Token shows “missing” → ensure the env var is set in the same shell you launch R from.
- HTTP 403 → token not sent or invalid.
- HTTP 400 → SoQL syntax error. Try
SELECT * LIMIT 10. - Port busy → change the port, e.g.
port=8888. - Nothing loads → open http://localhost:8080 manually.
app.R— Shiny UI/server (theme, grouped stats plot, downloads)R/socrata_v2.R— robust SODA v2 client (raw→UTF-8, SoQL paging)install.R— installs CRAN depsconfig.yml— domain, defaultview_id, and token env var
MIT