Skip to content

New Dashboard

Scaffold a data dashboard that reads from an existing database and presents it cleanly. Defaults to Streamlit; uses Shiny for Python when you want reactive, finer-grained UI control.

Trigger: /new-dashboard

How It Works

  1. Choose framework (Streamlit or Shiny), data source (Turso, DuckDB/MotherDuck, SQLite, Parquet), and the tables/metrics to show.
  2. Scaffold app.py, a cached data.py access layer, a components/ directory, config, and .env.example.
  3. Wire up pre-commit — generate .pre-commit-config.yaml (same hook set as New Project) and run pre-commit install before the first commit.
  4. Isolate data access — all queries live in data.py behind cached functions; the UI never opens a connection inline.
  5. Env-driven connection — local file for dev, cloud DB when the env var is set.
  6. Layout — title, filter sidebar, headline metrics, then honest high-density charts.
  7. Run/deploy note in the README; hand off shipping to Deploy Streamlit.

Cached, Isolated Data Access

Bad: query in the render path

conn = duckdb.connect("md:trading")            # reconnects every rerun
df = conn.execute("SELECT * FROM trades").df() # re-runs on every interaction

Good: cached function, env-driven

@st.cache_resource
def _conn():
    return duckdb.connect(os.environ.get("DATABASE_URL", "local.duckdb"))

@st.cache_data(ttl=300)
def load_trades(since: str):
    return _conn().execute("SELECT * FROM trades WHERE exit_time >= ?", [since]).df()

Streamlit vs Shiny

Choose When
Streamlit Fast build, simple top-to-bottom apps
Shiny for Python Reactive dependencies, modules, tighter layout control

Notes

  • Cache aggressively but set a TTL on live data, or the dashboard silently shows stale numbers.
  • Keep all SQL in data.py — mixing queries into UI code makes the app untestable and slow.
  • Never commit the Turso/MotherDuck token; use secrets or environment variables.
  • Defer chart styling to Data Visualization; defer deployment to Deploy Streamlit.