Public
Edited
Apr 13
10 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
iframe_location = document.location // we are inside the sandbox, so the document is the iframe
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
runtime_variables = [...runtime._variables].map(toObject)
Insert cell
Insert cell
Insert cell
Insert cell
builtin_variables = toMap(
...[...runtime._variables].filter((v) => v._module === builtin_module_ref)
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
main_cells = cellMap(main)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof_ast = parser.parseCell("viewof foo = 'bar'")
Insert cell
mutable_ast = parser.parseCell("mutable foo = 'bar'")
Insert cell
async_ast = parser.parseCell("foo = { await ''}")
Insert cell
generator_ast = parser.parseCell("foo = { yield 'async'}")
Insert cell
fileattachment_ast = parser.parseCell("foo = FileAttachment('filepath')")
Insert cell
viewof_ref_ast = parser.parseCell("foo = viewof bar")
Insert cell
import_ast = parser.parseCell("import {foo} from 'blah'")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
compiled_variables = compile("mutable example = 12")
Insert cell
Insert cell
Insert cell
observable = import(
"https://cdn.jsdelivr.net/npm/@observablehq/runtime@5/dist/runtime.js"
)
Insert cell
embedded_runtime = new observable.Runtime()
Insert cell
Insert cell
embedded_main = embedded_runtime.module()
Insert cell
Insert cell
embedded_variables = compiled_variables.map((v) =>
embedded_main
.variable({})
.define(v._name, v._inputs, toFunction(v._definition))
)
Insert cell
Insert cell
Insert cell
{
await new Promise((r) => setTimeout(r, 1000));
return embedded_variables[0]._promise;
}
Insert cell
Insert cell
Insert cell
Generators.observe((notify) => {
// Generator.observe is a notebook userspace concept to make emitting values simpler
embedded_main
.variable({
fulfilled: (value) => {
// Observer.fulfilled
notify(value); // pipe the variable notification up to userspace
}
})
.define(async function* () {
// zero input async generator
// this is pure JS, normally the output a compile step
// is used here
let i = 0;
while (true) {
await new Promise((resolve) => setTimeout(resolve, 1000));
yield i++;
}
});
})
Insert cell
Insert cell
Insert cell
<div></div> <!-- DOM container we will pipe changes to -->
Insert cell
inspector = new observable.Inspector(cell_out) // connect Inspector to our DOM node
Insert cell
Generators.observe((notify) => {
// Generator.observe is a notebook userspace concept to make emitting values simpler
embedded_main.variable(inspector).define(async function* () {
// zero input async generator
// this is pure JS, normally the output a compile step
// is used here
let i = 0;
while (true) {
await new Promise((resolve) => setTimeout(resolve, 1000));
yield i++;
}
});
})
Insert cell
Insert cell
notebook_observer = main._scope.get("title_cell")._observer
Insert cell
notebook_observer.mode
Insert cell
Insert cell
main._scope.get("title_cell")._observer._node.innerHTML
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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