Platform
Resources
Pricing
Sign in
Get started
Tom Larkworthy
Tech Lead at Taktile. Formerly Firebase, Google
Workspace
Fork
Public
lopecode
By
Tom Larkworthy
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.
Try it for free
Learn more
Fork
View
Export
title_cell
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cell_map_diagram
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
iframe_location
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
runtime_reference
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
runtime_variables
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
builtin_module_ref
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
builtin_module
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
builtin_variables
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
main_cells
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cell_variables
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cell_variables_table
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
example_mutable
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
viewof_ast
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
mutable_ast
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
async_ast
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
generator_ast
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
fileattachment_ast
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
viewof_ref_ast
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
import_ast
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
compiled_variables
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
observable
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
embedded_runtime
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
embedded_main
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
embedded_variables
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
toFunction
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cell_out
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
inspector
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
notebook_observer
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
toMap
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
toObject
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML