Data Apps
What a data app is (HTML and JavaScript shipped in a package's public/ folder), how to build one with the agent, how it gets its data, and how to write the page script yourself
A data app is a web page, or a set of pages, built in plain HTML and JavaScript and shipped inside a package. It gets its data the same way every other surface does: by querying the package's data model through Credible. The same definitions apply, and so do the model's access rules, for whoever is viewing it.
Use a data app when a report isn't enough: a custom layout, an interactive tool, or a page built for one audience.
Open a Data App
Data apps are listed in the Data apps section of their package's page. Open one there, or from the package in a workspace.
Build a Data App with the Agent
You don't need to write code to build a data app. In the Credible App, ask in a modeling chat on a draft package; with your coding agent, ask in a directory set up with the Cred CLI. See Model Your Data for the two.
- Describe the app: the charts, filters and layout, for example "a revenue dashboard with monthly trends, filterable by region".
- Iterate. The agent writes the app into the package's
public/folder, reading field names from the model. Preview it and ask for changes in plain language. With your coding agent, the local Publisher reloads the open page as you edit. - Publish the package. The app ships with the package version it was built against and is listed on the package's page.
How a Data App Gets Its Data
A package becomes a data app by having a public/ folder:
my-package/
├── publisher.json # package manifest
├── orders.malloy # the models: not served
└── public/ # the app: served
├── index.html
└── app.jsOnly public/ is served to the browser. The models, data files and manifest are not. The page asks Credible to run Malloy queries against the package's models, and Credible runs each one as the person viewing the page, with that person's access. Two viewers with different access can see different numbers in the same app.
The app ships with its package and updates with the model: publishing a new version publishes the app and the models it reads together.
Writing the Page Script Yourself
Credible serves packages with Publisher, the open-source Malloy engine it runs. Publisher provides the data-app script, /sdk/publisher.js. Each page loads it with a root-relative script tag, so the same page works in any environment or package:
<script src="/sdk/publisher.js"></script>
<script>
Publisher.query("orders.malloy", "run: orders -> by_month").then((rows) => {
renderChart(rows);
});
</script>Publisher.query is the function the script provides for querying: it runs a Malloy query against one model in the package and returns the rows. Publisher.queryFull takes the same arguments and returns the full result.
- Pass a viewer's choice with
givens, not by building the query string from user input. Givens are bound as typed parameters, so the value is never pasted into query text. They are parameters, not access control: what a viewer can read comes from the model's access rules and the viewer's identity. - Load the script on every page. It also reports the page's height so Credible can size the frame. A page that doesn't load it can't query its package.
- Hand a question to the agent. When the app is open in the Credible app, a page can post
{ type: "credible:chat-message", prompt: "..." }towindow.parent. The Credible app opens the chat beside the app and sends the prompt to the agent.
The full runtime API, including the query options, is in Publisher's HTML data apps reference (opens in a new tab).