Public
Edited
Nov 23, 2024
Importers
14 stars
Insert cell
Insert cell
helloWorldNB = ({
files: [],
nodes: [
{
id: 1,
value: "md`# ${h} ${w}`",
mode: "js"
},
{
id: 2,
value: "h = \"Hello\"",
mode: "js"
},
{
id: 3,
value: "w = \"World\"",
mode: "js"
},
{
id: 4,
value: "mol = 42",
mode: "js"
},
{
id: 5,
value: "mol2 = mol + 2 - 1 * 2",
mode: "js"
}
]
})

Insert cell
Insert cell
plotNB = compilerMod.download('https://observablehq.com/@observablehq/plot');
Insert cell
Insert cell
compiledHelloWorld = compilerMod.compile(helloWorldNB);
Insert cell
compiledPlot = compilerMod.compile(plotNB);
Insert cell
Insert cell
Insert cell
```js
${compiledHelloWorld.toString()}
```
Insert cell
Insert cell
Insert cell
`\n${compiledPlot.toString()}\n`
Insert cell
Insert cell
compiledPlot.fileAttachments
Insert cell
compiledPlot.cells
Insert cell
Insert cell
Insert cell

viewof div = {
const placeholder = DOM.element('div');
placeholder.style.border="1px solid darkGray"
placeholder.style.padding="4px";
const library = new runtimeMod.Library();
const runtime = new runtimeMod.Runtime(library);
compiledHelloWorld(runtime, name => {
const div = DOM.element('div');
placeholder.appendChild(div);
return new runtimeMod.Inspector(div);
});
return placeholder;
}

Insert cell
Insert cell
viewof div2 = {
const placeholder = DOM.element('div');
placeholder.style.border="1px solid darkGray"
placeholder.style.height="600px";
placeholder.style.padding="4px";
placeholder.style.overflowY="scroll";
const library = new runtimeMod.Library();
const runtime = new runtimeMod.Runtime(library);
compiledPlot(runtime, name => {
const div = DOM.element('div');
placeholder.appendChild(div);
return new runtimeMod.Inspector(div);
});
return placeholder;
}
Insert cell
Insert cell
compilerMod.ojs2notebook(`
a = 1
b = 2
c = a + b
d = {
yield 1;
yield 2;
yield 3;
}

viewof e = {
let output = {};
let listeners = [];
output.value = 10;
output.addEventListener = (listener) => listeners.push(listener);;
output.removeEventListener = (listener) => {
listeners = listeners.filter(l => l !== listener);
};
return output;
}
`)
Insert cell
Insert cell
omdNB = compilerMod.omd2notebook(`\
# Hello and welcome to OMD Markdown!

Lets create a var:

\`\`\`
a = 1
\`\`\`

Lets create b var:

\`\`\`
b = 2
\`\`\`

And now lets add them:

\`\`\`
c = a + b
\`\`\`
`)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
async function *renderNotebook(nb) {
const placeholder = DOM.element('div');
placeholder.style.border="1px solid darkGray"
placeholder.style.padding="4px";
yield placeholder;
const library = new runtimeMod.Library();
const runtime = new runtimeMod.Runtime(library);
const nbCompiled = await compilerMod.compile(nb);
nbCompiled(runtime, name => {
const div = DOM.element('div');
placeholder.appendChild(div);
return new runtimeMod.Inspector(div);
});
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more