Skip to content

Get started

A dashboard is a few HTML tags: <score-card>, <bar-chart>, <data-table>, <ui-filter>. A tag says what to show; it does not know where the data comes from. That part is yours to choose, and there are three setups.

Choose your setup

Two questions decide:

  1. Who writes the dashboard? You, or someone you cannot trust with your page: a language model, another user.
  2. Who answers the queries? The browser, on a file it downloads, or your server, query by query.
Who writes the dashboard Who answers the queries Setup
A report, a page of your site, a dashboard per customer You The browser, on a file: public, or served to each viewer with their own rows 1 · Static page
The dashboards of your product You Your server, with access rules 2 · Your backend
Generative BI, dashboards built by your users A model, or your users Your server, with access rules 3 · Sandbox

New to the project? Do the static page first: five minutes, no server, and every other setup uses the same tags.

1 · Static page

Your pageThe tags, written by you
SQL, built by the components
DuckDB-WASMA database inside the browser
downloads once
Data filesCSV, Parquet, JSON, or records pushed by a script
<source-table name="orders" url="orders.csv" date-column="date"></source-table>

<score-card title="Revenue" table="orders" measure="sum(revenue)" format="eur"></score-card>
<bar-chart table="orders" measure="sum(revenue)" by="country"></bar-chart>

<script src="https://unytics.io/bi-components/dist/bi-components.js" defer></script>
  • You add <source-table>, and table="..." on each component. Measures are SQL expressions.
  • Choose it when what a viewer may see fits in a file. The file is served as your page is: to anyone, to signed-in users only, or written for each viewer with only their rows.
  • No query server: any host works, from a Markdown site such as this one to your own application.

Static page guide Live example

2 · Your backend

Your pageThe tags, written by you
one POST per render: "revenue by country"
Your APIChecks each query, applies the rights of the signed-in user
your SQL
Your dataWarehouse, database, semantic layer
<source-api url="/api/queries"></source-api>

<score-card measure="revenue" compare="yoy"></score-card>
<bar-chart measure="revenue" by="country"></bar-chart>

<script src="https://unytics.io/bi-components/dist/bi-components.js" defer></script>
  • You add <source-api>, and one endpoint on your server. The components send named measures, SQL expressions or named queries: your endpoint accepts those you choose.
  • Choose it when you write the dashboards yourself and the data must stay on your server: too large to download, or computed by your own engine.
  • Not for a dashboard written by someone else: its scripts would run in your page. That is setup 3.

Backend guide Live example

3 · Sandbox

Sandboxed frameThe dashboard, written by a model or a user. No network, no access to your page
asks: "revenue by country"
Your pageembedDashboard validates each query, then calls your resolveQuery
your call
Your APIChecks again, applies the viewer's rights, answers
import { embedDashboard } from 'https://unytics.io/bi-components/dist/bi-components-host.js';

embedDashboard(document.getElementById('dashboard'), {
  html: dashboardHtml,                       // written by a model or a user: untrusted
  resolveQuery: (query) => fetch('/api/query', { method: 'POST', body: JSON.stringify(query) }).then((r) => r.json()),
});
  • You add one call to embedDashboard in your page, and a function that answers a query.
  • Choose it when you do not write the dashboard: a model generates it, or your users build and share their own.
  • What you get: the dashboard can only ask your page for data. It cannot read your page, your cookies or the network, and it sees what its viewer may see, whoever wrote it.

Sandbox guide Generative AI guide Playground

Side by side

1 · Static page 2 · Your backend 3 · Sandbox
Dashboard written by You You A model, your users
Queries answered by DuckDB-WASM, in the browser Your server Your server, through your page
What you add <source-table> <source-api> and one endpoint embedDashboard() and resolveQuery
File to load bi-components.js bi-components.js bi-components-host.js
Queries name data with SQL expressions, and the views of the page by their names Named measures, SQL expressions, named queries: those your server accepts The same as your backend
Access rules Whoever may download the file: serve it to whom you choose, with the rows you choose Your server, on every query Your server, on every query
Server code None One endpoint Usually one endpoint

An application often uses two of them: setup 2 for the dashboards its team writes, setup 3 for those its users generate. Both can call the same endpoint.

Three ways to ask for data

The tags are the same everywhere. What changes is how a query names what it wants:

SQL expressions Named measures Named queries
Written <bar-chart table="orders" measure="sum(revenue)" by="country"> <bar-chart measure="revenue" by="country"> dashboard.query('category_mix'), in a script
Who knows what it means The page: the expression is written there Your server: a semantic layer, dbt metrics, a dictionary in your code Your server: it holds the whole query
Extras Any SQL aggregate or expression compare="yoy", granularity="month", formats and labels given by the server Rows of any shape, for a custom chart
Static page ✓ ✓ a <source-view> of the page
Your backend, sandbox ✓ checked by your server ✓ ✓

One endpoint can accept all three, and refuse what it does not want: a server that knows no measures refuses names, one that exposes no table refuses SQL expressions. Named measures give one definition of each figure, and they are what a language model handles best. SQL expressions need no definition at all. Answer the queries shows how a server handles each; Components lists the attributes of the tags.

How it fits together

Every component, and every script you write, talks to a single object: window.dashboard. It runs queries and holds the filters, the period and the theme. Each setup installs its own version of it, which is why a dashboard does not change when the setup does.

 <score-card>  <bar-chart>  <data-table>  <ui-filter>  your scripts
        \           |            |            |           /
         +---------------- window.dashboard ---------------+
              |                    |                    |
       1 · Static page       2 · Your backend       3 · Sandbox
       <source-table>        <source-api>           embedDashboard()
       DuckDB-WASM           POST to your API       postMessage to your page

Next

  • Components: every tag and its attributes, with live examples.
  • Answer the queries: what your server receives and what it returns, for setups 2 and 3.
  • Generative AI: the system prompt and the loop that make a model write dashboards.
  • React, Vue, Svelte: the tags in a component, data from your state, a sandbox in a component.
  • Install and versions: the two files, a CDN or npm, pinning a version.
  • Examples: working pages for each setup, with their source.