Loading...
Loading...
Guide for creating Observable Notebooks 2.0, the open-source notebook system for interactive data visualization and exploration. Use this skill when creating, editing, or building Observable notebooks.
npx skill4agent add maragudk/skills observable-notebooksnpm add @observablehq/notebook-kitnotebooks preview notebook.html
notebooks preview --root ./notebooks
notebooks preview --template template.tmpl notebook.htmlnotebooks build notebook.html
notebooks build --root ./notebooks -- *.html.observablehq/dist/notebooks download https://observablehq.com/@d3/bar-chart > bar-chart.htmlnotebooks query --database duckdb 'SELECT * FROM data'<notebook><notebook>
<title>My Notebook</title>
<script type="text/markdown">
# Introduction
This is a markdown cell with interpolation: ${1 + 1}
</script>
<script type="module">
const data = [1, 2, 3, 4, 5];
display(data);
</script>
<script type="module">
import * as Plot from "npm:@observablehq/plot";
display(Plot.barY(data).plot());
</script>
</notebook><script>| Type | Script Attribute | Description |
|---|---|---|
| JavaScript | | Standard ES modules, |
| TypeScript | | TypeScript with type checking |
| Markdown | | CommonMark with |
| HTML | | HTML with auto-escaped interpolation |
| SQL | | Database queries |
| TeX | | LaTeX equations |
| Graphviz | | DOT diagram notation |
| Python | | Python code (data loaders) |
| R | | R code (data loaders) |
| Node.js | | Node.js data loaders |
pinnedhiddenid="123"database="mydb"format="json"output="varname"<script type="module" pinned>
const x = 42;
display(x);
</script>
<script type="application/sql" database="duckdb" output="results">
select * from data limit 10
</script><script type="module">
const a = 10;
</script>
<script type="module">
const b = 20;
</script>
<script type="module">
// This cell re-runs whenever a or b changes
display(a + b);
</script>display(value)view(input)FileAttachment(path)invalidationvisibilitywidthnowInputs.range()Inputs.select()Plot.barY()Plot.line()<script type="module">
import confetti from "npm:canvas-confetti";
confetti();
</script><script type="module">
const gain = view(Inputs.range([0, 11], {
value: 5,
step: 0.1,
label: "Gain"
}));
</script>
<script type="module">
// This cell re-runs when the slider changes
display(`Current gain: ${gain}`);
</script>Inputs.button(label)Inputs.toggle({label, value})Inputs.checkbox(options, {label})Inputs.radio(options, {label})Inputs.range([min, max], {value, step, label})Inputs.select(options, {label, multiple})Inputs.text({label, placeholder})Inputs.textarea({label, rows})Inputs.date({label, value})Inputs.color({label, value})Inputs.file({label, accept})Inputs.search(data, {label})Inputs.table(data, {columns})<script type="module">
const data = [
{year: 2020, value: 10},
{year: 2021, value: 20},
{year: 2022, value: 15}
];
display(Plot.plot({
marks: [
Plot.barY(data, {x: "year", y: "value"})
]
}));
</script>Plot.dot()Plot.line()Plot.barX()Plot.barY()Plot.areaY()Plot.rectY()Plot.text()Plot.ruleX()Plot.ruleY()<script type="module">
const data = await FileAttachment("data.csv").csv({typed: true});
display(Inputs.table(data));
</script>.csv().json().tsv().text().blob().arrayBuffer().image().xlsx().zip()<script type="module">
const response = await fetch("https://api.example.com/data");
const data = await response.json();
display(data);
</script><script type="application/sql" database="duckdb" output="results">
select * from "data.parquet" limit 100
</script>
<script type="module">
display(Inputs.table(results));
</script><notebook theme="dark">
...
</notebook>aircoffeecottondeep-spaceglacierinkmidnightnear-midnightocean-floorparchmentslatestarksun-faded<!-- template.tmpl -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="generator" content="Observable Notebook Kit">
<title>My Site</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>My Site Header</header>
<main></main>
<footer>My Site Footer</footer>
</body>
</html>notebooks build --template template.tmpl -- *.html<main><notebook theme="slate">
<title>Sales Dashboard</title>
<script type="text/markdown">
# Sales Dashboard
Interactive visualization of quarterly sales data.
</script>
<script type="module">
const sales = await FileAttachment("sales.csv").csv({typed: true});
</script>
<script type="module">
const quarter = view(Inputs.select(
["Q1", "Q2", "Q3", "Q4"],
{label: "Quarter", value: "Q1"}
));
</script>
<script type="module">
const filtered = sales.filter(d => d.quarter === quarter);
display(Plot.plot({
title: `Sales for ${quarter}`,
marks: [
Plot.barY(filtered, {
x: "product",
y: "revenue",
fill: "category"
}),
Plot.ruleY([0])
]
}));
</script>
<script type="module" pinned>
display(Inputs.table(filtered, {
columns: ["product", "category", "revenue", "units"]
}));
</script>
</notebook>