# BI Components > AI-generated dashboards, safe to embed. Open-source HTML tags for dashboards: sandboxed, no build step. --- Page: Home Address: https://unytics.io/bi-components/
Open source · no build step # AI-generated dashboards, safe to embed **BI Components** are HTML tags like ``. Write a dashboard by hand, or let a language model write it for your users: it runs in a sandbox, on your data, with the rights of the person looking at it.
[Open the playground](https://unytics.io/bi-components/examples/playground/){ .md-button .md-button--primary } [Get started](guides/index.md){ .md-button }
The playground: a conversation on the left, the dashboard it produced on the right

## A dashboard is a few lines of HTML This is the whole source of the dashboard below. It is live: click a bar to filter the rest, `Ctrl` / `Cmd` + click to select several. === "Result"
- - -
=== "HTML" ``` html ``` No build step, no framework, nothing to install. The tags describe *what* to show; where the data comes from is a separate choice, and there are three.
## Three ways to use it The same tags work in three setups. Which one you need depends on **who writes the dashboard** and **where the data is**.
- 1 · Static page **You write the dashboard. The data is a file.** The browser downloads a CSV, Parquet or JSON file and queries it locally with DuckDB-WASM. The file can be public, or served to each viewer with their own rows. No query server. ``` html ``` For reports, documentation, prototypes, a dashboard per customer. The dashboard above works this way. [Guide](guides/static-page.md) · [Example](https://unytics.io/bi-components/examples/sales-dashboard/) - 2 · Your backend **You write the dashboard. The data stays on your server.** The components send their queries to one endpoint of your API, which answers with the rights of the signed-in user. Named measures, SQL expressions or named queries: it accepts those you choose. ``` html ``` For the dashboards of your own product, on your own engine and access rules. [Guide](guides/backend.md) · [Example](examples/fastapi-direct.md) - 3 · Sandbox **A model or your users write the dashboard.** Untrusted HTML runs in an isolated frame with no network access. Your application checks and answers every query. ``` js embedDashboard(element, { html, resolveQuery }) ``` For generative BI, "chat with your data", dashboards your customers build and share. [Guide](guides/sandbox.md) · [Example](https://unytics.io/bi-components/examples/playground/)
[Compare the three setups and pick yours](guides/index.md){ .md-button }
## Made for generated dashboards Letting a model write what your users will run is first a security question. The third setup is where most of the work went.
- **A grammar a model gets right** A dozen declarative tags and a handful of attributes. The [system prompt](guides/generative-ai.md#the-system-prompt) that teaches them fits on one screen. - **A sandbox for what it writes** Generated HTML and JavaScript run in an isolated frame with no network access. They cannot read your application, its cookies or its tokens. - **A semantic layer, or SQL expressions** Give the model the names of your measures (`revenue`, `margin_rate`), or let it write SQL expressions on tables you expose. Either way your application checks every request before it runs. - **The viewer's rights, always** Every query is validated and answered by your application, which applies row-level security for the person looking at the dashboard, whoever wrote it. - **Custom charts, contained** When no component fits, the model writes a script with ECharts and the same data access as the components. It runs in the same sandbox. - **Errors that correct themselves** A refused query shows its reason in the component. Send that text back to the model and the next version is fixed.
The [playground](https://unytics.io/bi-components/examples/playground/) shows the result: a chat on the left, the dashboards it produced on the right, the HTML behind each of them, and a hostile dashboard being stopped. The [Generative AI guide](guides/generative-ai.md) explains how to build it on your data.
## Where to go next
- **[Get started](guides/index.md)** The three setups side by side, and a first dashboard in five minutes. - **[Components](components.md)** Every tag and its attributes, with live examples. - **[Examples](examples/README.md)** Working pages for each setup, with their source.

## Open source BI Components is MIT licensed, on [GitHub](https://github.com/unytics/bi-components), and made by [Unytics](https://unytics.io). It is built on [Apache ECharts](https://echarts.apache.org/), [DuckDB-WASM](https://duckdb.org/docs/api/wasm/overview) and standard [Web Components](https://developer.mozilla.org/en-US/docs/Web/API/Web_Components). --- Page: Components Address: https://unytics.io/bi-components/components/ # Components Every tag, with its attributes. The tags are the same in the three [setups](guides/index.md); one script makes them work: ``` html ``` | | Tags | |---|---| | [Charts](#charts) | `` `` `` `` | | [Key figures](#key-figures) | `` `` | | [Tables](#tables) | `` | | [Filters](#filters) | `` `` | | [Data sources](#data-sources) | `` `` `` | | [Explore a table](#explore-a-table) | `` `` `` | The examples of this page are live. They form one dashboard, a [static page](guides/static-page.md) on a CSV file of orders: click a bar, a slice or a row and everything else on the page is filtered. ``` html ``` ## Naming data A component names what it shows in one of two ways. The `table` attribute decides. | | With `table`: **SQL expressions** | Without `table`: **named measures** | |---|---|---| | Example | `` | `` | | `measure` is | Any SQL aggregate: `sum(revenue)`, `count(distinct customer)`, `sum(a) / sum(b)` | A name your server knows: `revenue` | | `by` is | A column or a SQL expression: `country`, `date_trunc('month', date)` | A name your server knows: `country` | | Who computes it | The database named by `table` | Your server, its own way | | Used in | Every setup: a [static page](guides/static-page.md); [your backend](guides/backend.md) or a [sandbox](guides/sandbox.md) whose server accepts them | [Your backend](guides/backend.md); a [sandbox](guides/sandbox.md) | A script has a third way, for a custom chart: a query by its name, `dashboard.query('category_mix')`, whose definition is on your server, or a `` of a static page. See [Answer the queries](guides/query-engine.md#three-kinds-of-queries). The examples below use SQL expressions, since this page has no server. With named measures the same tags are shorter, and get a few more attributes: see [the last column](#common-attributes) and the [dashboard on a FastAPI backend](examples/fastapi-direct.md). ## Common attributes Shared by charts, key figures and tables. An attribute changed after the first render, by a script or a framework, is followed: the component asks again if its query changed, and draws again otherwise. | Attribute | | SQL expressions | Named measures | |---|---|:-:|:-:| | `table` | The table to query: a `` or `` of the page, or a table your Host exposes. Its presence selects SQL expressions. | ✓ | | | `measure` | What to compute. One per chart or key figure. | ✓ | ✓ | | `measures` | Several, separated by commas. `` only. | ✓ | ✓ | | `by` | The dimension to split by. Clicking one of its values filters the other components. | ✓ | ✓ | | `breakdown-by` | A second dimension: one series per value. | ✓ | ✓ | | `sort-by` | A measure or a dimension, with an optional direction: `sort-by="sum(revenue) desc"`. Also written `order_by`. | ✓ | ✓ | | `limit` | The number of rows. | ✓ | ✓ | | `format` | `eur`, `pct`, `int` or `dec`: see [number formats](guides/customization.md#number-formats). With named measures, your server can give it. | ✓ | ✓ | | `title` | A title above the component. | ✓ | ✓ | | `where` | A SQL condition for this component only. Static page only. | ✓ | | | `date-column` | The column the period applies to, when it is not the one of the table. | ✓ | | | `breakdown-limit` | With `breakdown-by`: how many series to keep, the biggest first (6). | ✓ | | | `granularity` | A time series: `day`, `week`, `month`, `quarter` or `year`, with no `by`. | | ✓ | | `compare` | A comparison with another period: `yoy`, `mom` or `prev_period`. | | ✓ | | `attributes` | Columns that describe a dimension, for a table: `attributes="city, manager"`. | ✓ | ✓ | | `param-*` | Anything else your server understands: `param-scope="like_for_like"`. | ✓ | ✓ | An alias gives the displayed name of an expression: `measure="sum(revenue) as Revenue"`. `granularity` and `compare` written without a value follow the page: a `` or `` then drives every component at once. ## Charts Charts take `height` (`400px` by default) and `hide-axis-names`. Without `sort-by`, a chart follows its dimension (time, then A to Z); horizontal bars and pies show the biggest values first. ### Bar chart === "Result" === "HTML" ``` html ``` `horizontal` makes a ranking, `limit` keeps the first rows: === "Result" === "HTML" ``` html ``` `breakdown-by` makes one series per value, side by side or `stacked`: === "Result" === "HTML" ``` html ``` ### Line chart A dimension holding dates gets a time axis. === "Result" === "HTML" ``` html ``` `stacked` adds the series up. With named measures, a time series needs no `by`, and `compare` draws the other period as a dashed line: ``` html ``` ### Pie and doughnut chart === "Result"
=== "HTML" ``` html ``` ## Key figures ### Score card One figure with its title. Without `title`, the name of the measure is used, or the label your server gives. === "Result"
- - -
=== "HTML" ``` html ``` With named measures, `compare` adds a colored badge with the variation against the other period: ``` html ``` `format` also takes a spreadsheet pattern here: `format="#,##0.0"`. ### Simple value The figure alone, to place in a sentence or a title. === "Result" The shop took orders from countries. === "HTML" ``` html The shop took orders from countries. ``` ## Tables ### Data table Several measures, with columns always shown in the declared order: dimensions, attributes, measures. Click a column header to sort, click a row to filter the other components (`Ctrl` / `Cmd` + click to select several rows). === "Result" === "HTML" ``` html ``` | Attribute | | |---|---| | `by` | One or several dimensions: `by="country, channel"`. A click on a row filters on the first. | | `measures` | Several measures. Commas inside parentheses do not split: `round(avg(revenue), 2)` is one measure. | | `formats` | A format per column: `formats="Revenue:eur, Orders:int"`. | | `max-height` | The height from which the table scrolls, under a fixed header: `max-height="400px"`. | ## Filters Filters apply to the whole page: every component asks again with the new selection. ### Period Quick presets and two dates. It applies to the tables that declare a `date-column`, or is sent to your server. === "Result" === "HTML" ``` html ``` | Attribute | | |---|---| | `presets` | Among `all`, `7d`, `30d`, `90d`, `365d` (any number of days), `mtd` and `ytd`. | | `max` | The last day of the presets, when it is not today: the last day of your data. | | `default` | The period at start: a preset (`default="90d"`) or two dates (`default="2026-06-01, 2026-11-29"`). | ### Dimension filter === "Result" === "HTML" ``` html ``` | Attribute | | |---|---| | `dimension` | The dimension to filter on. | | `type` | `select` (default), `segmented` (buttons) or `toggle` (a checkbox). | | `options` | The choices: `options="Web, Store"`, or with labels `options="web:Online, store:In store"`. Without it, the values are read from the data: from `table`, or asked to your server. | | `table` | Where to read the values, with SQL expressions. | | `label` | The text before the control. `label=""` for none. | | `multiple` | A select that takes several values. | | `value` | For a toggle on a dimension: the value it filters on. | | `default` | The selection at start: `default="Web"`, `default="Web, Store"`. | ### Option of the page With `option` instead of `dimension`, the control sets an option of the page rather than a filter. Two options are known to the components, and you can add your own: ``` html ``` How your server reads an option of your own: [Your own parameters](guides/query-engine.md#your-own-parameters). ## Data sources Invisible elements that say where the data comes from. A page has either `` and `` elements, or one ``. A dashboard in a [sandbox](guides/sandbox.md) has none: its Host answers. ### Source table Loads a file, or records given by a script, into the database of the browser: the [static page setup](guides/static-page.md). ``` html ``` | Attribute | | |---|---| | `name` | The name components use in `table="..."`. | | `url` | A Parquet, CSV or JSON file, or an API that returns JSON. | | `columns` | The columns to keep or compute, as in a SQL `select`. `*` by default. | | `date-column` | The column the period of the page applies to. | | `format` | `parquet`, `csv`, `tsv` or `json`, when the address does not end with it. | Without `url`: set `element.data = records`, then call `element.load(true)`. It emits `data-loaded` when its data is ready. ### Source view A SQL query over the tables of the page, used as a table. ``` html select date, sum(revenue) as revenue from orders group by 1 order by 2 desc limit 5 ``` `name` and `date-column` as above. A script reads it with `window.dashboard.query('top_days')`. ### Source API Sends the queries of the page to your server, one `POST` per render: the [backend setup](guides/backend.md). The components then use named measures. ``` html ``` | Attribute | | |---|---| | `url` | Where the queries go, relative to the page. | | `body` | A JSON object added to every request. | | `credentials` | `same-origin` (default) or `include`, for an API on another site. | Its `headers` and `body` properties take an object or a function: see [Who is looking](guides/backend.md#who-is-looking). ## Explore a table Three components to look at a dataset before building its dashboard. ### Bar chart grid One small chart per dimension, all filtering each other. Without `by`, every text column of the table gets its chart. === "Result" === "HTML" ``` html ``` With SQL expressions, each chart shows shares of the total, and the tool at its top right breaks the other charts down by its dimension. `time-by` adds line charts above the bars, one per value: a date column with SQL expressions (`time-by="date"`), a granularity with named measures (`time-by="month"`). ### Tables and columns In a static page, `` lists the tables of the page and `` the columns of one: === "Result" === "HTML" ``` html ``` ## What every component does - **It waits.** A grey placeholder is shown until the first answer, and the content is dimmed while a new one loads. - **It says when there is nothing**: "No data" for an empty answer. - **It shows its error**: an unknown table or measure, a refused query. The text comes from the database or from your server, and it is what to give back to a model that wrote the dashboard. - **It filters the page**: a click on a value of its `by` dimension selects it, `Ctrl` / `Cmd` + click adds to the selection, a second click or a click on the background removes it. The clicked component keeps showing every value, with the selection highlighted. - **It follows the theme** of the page: see [Theme, formats, language](guides/customization.md). When no component fits, write the chart yourself: [Custom charts and scripts](guides/custom-charts.md). --- Page: All examples Address: https://unytics.io/bi-components/examples/ # Examples Working pages for each of the three [setups](../guides/index.md). Every example is in the repository: open it, then read its source. ## Start with the playground
- 3 · Sandbox **[Playground](https://unytics.io/bi-components/examples/playground/)** 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. [Open the playground](https://unytics.io/bi-components/examples/playground/){ .md-button .md-button--primary } [Source](https://github.com/unytics/bi-components/tree/main/docs/examples/playground) · [Guide](../guides/generative-ai.md)
## 1 · Static page You write the dashboard, the browser queries a file with DuckDB-WASM. No backend: `` loads the data and every component uses `table="..."`. [Guide](../guides/static-page.md) | Example | What it shows | Source | |---|---|---| | [Sales dashboard](sales-dashboard/index.html) | 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](https://github.com/unytics/bi-components/tree/main/docs/examples/sales-dashboard) | | [GitHub stars](github-stars.md) | Data fetched from an API by a script, then pushed into a source table. | [GitHub](https://github.com/unytics/bi-components/blob/main/docs/examples/github-stars.md) | | [Conference proposals](conference-proposals.md) | A nested JSON answer made flat by a SQL view, and a grid of charts to explore it. | [GitHub](https://github.com/unytics/bi-components/blob/main/docs/examples/conference-proposals.md) | ## 2 · Your backend You write the dashboard, your server answers. No frame and no DuckDB-WASM: `` sends the queries of the page to one endpoint, one `POST` per render. [Guide](../guides/backend.md) | Example | What it shows | Source | |---|---|---| | [A dashboard on a FastAPI backend](fastapi-direct.md) | 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. The server answers named measures only; an endpoint can also accept SQL expressions and named queries ([guide](../guides/backend.md#3-sql-expressions-and-named-queries)). | [GitHub](https://github.com/unytics/bi-components/blob/main/docs/examples/fastapi-direct.md) | ## 3 · Sandbox Someone else writes the dashboard: a model, another user. It lives in `