Examples¶
Working pages for each of the three setups. Every example is in the repository: open it, then read its source.
Start with the playground¶
-
3 · Sandbox
What generative BI looks like with BI Components: recorded conversations on the left, the dashboards they produced on the right, with the HTML and the system prompt behind them.
It is not connected to a model; everything after the model is real: the sandboxed frame, queries answered by a DuckDB engine on the server, row-level security for the viewer, and a hostile dashboard being stopped.
1 · Static page¶
You write the dashboard, the browser queries a file with DuckDB-WASM. No backend: <source-table> loads the data and every component uses table="...". Guide
| Example | What it shows | Source |
|---|---|---|
| Sales dashboard | A local CSV file. Score cards, bar, line and pie charts, a table with several measures, period and dimension filters, a light and dark switch, cross-filtering with click and Ctrl / Cmd + click. |
GitHub |
| GitHub stars | Data fetched from an API by a script, then pushed into a source table. | GitHub |
| Conference proposals | A nested JSON answer made flat by a SQL view, and a grid of charts to explore it. | GitHub |
2 · Your backend¶
You write the dashboard, your server answers. No frame and no DuckDB-WASM: <source-api url="..."> sends the queries of the page to one endpoint, one POST per render. Guide
| Example | What it shows | Source |
|---|---|---|
| A dashboard on a FastAPI backend | A Markdown page of this site. Named measures (no table attribute), answered by the FastAPI server of the playground, used as it is. Score cards with a comparison, charts, a table, filters, and three viewer profiles whose row-level security is applied by the server. All the queries of a render travel in one request. |
GitHub |
3 · Sandbox¶
Someone else writes the dashboard: a model, another user. It lives in <iframe sandbox="allow-scripts"> with no network access, and the application around it (the Host) answers its queries. Guide
| Example | What it shows | Source |
|---|---|---|
| Playground | The chat product above, served by FastAPI: a static page and two endpoints. | GitHub |
| Playground, on Streamlit | The same playground served by Streamlit: the same interface as one full-page component, the same engine and the same answers. For teams already building with Streamlit. | GitHub |
| A Host with a semantic layer | A Host in a static page, with named measures. Generated dashboards including custom ECharts charts and a hostile page, a light and dark switch without reload, user profiles with row-level security, and a live view of the messages between the frame and the Host. | GitHub |
| A Host with direct queries | SQL expressions from the frame. The Host validates each query (validateTableSpec: the columns of orders only), compiles it to SQL, runs it in its own DuckDB-WASM and shows the SQL it ran. |
GitHub |
| In a Streamlit app | A sandboxed dashboard as one element of an ordinary Streamlit page, among native widgets: a select box for the viewer, a toggle for the theme, tabs. Queries are answered in Python by DuckDB, with row-level security. Start here to add dashboards to a Streamlit app. | GitHub |
The two playgrounds are interchangeable servers for one interface: an application needs only one. See Python, FastAPI, Streamlit.
Files of the semantic layer example:
host.html,host.js: the Host (controls,embedDashboard, security rules).presets.js: the dashboards given to the frame.mock_semantic_backend.js: a JavaScript simulation of a measures engine on fake data: 50 optical stores over 24 months.
Run them locally¶
Build the two files the sandboxed examples load, then serve the repository root with any static server:
npm ci && npm run build
python3 -m http.server 8000
Then open http://localhost:8000/docs/examples/sales-dashboard/, http://localhost:8000/docs/examples/sandbox-semantic-layer/host.html or http://localhost:8000/docs/examples/sandbox-direct-queries/host.html.
The Markdown examples are pages of the documentation site, served by mkdocs serve at the root of the repository (port 8000). The FastAPI one also needs the playground's server on another port, allowing that origin:
pip install -r docs/examples/playground/servers/fastapi/requirements.txt
CORS_ORIGINS=http://127.0.0.1:8000 uvicorn main:app --app-dir docs/examples/playground/servers/fastapi --port 8001
Then open http://127.0.0.1:8000/bi-components/examples/fastapi-direct/?api=http://127.0.0.1:8001/api/queries. On unytics.io the page and the server share one address, so neither is needed there.
The playground and the Streamlit example are Python applications: see their READMEs.
data/orders.csv is generated by node docs/examples/data/generate_orders.mjs. The pages load ECharts and DuckDB-WASM from the jsDelivr CDN, so the browser needs internet access. The sandboxed frames themselves can only download dist/bi-components.js, next to the dist/bi-components-host.js their Host imports.