Notebooks 2.0 is here.
Read the preview announcement
Platform
Resources
Pricing
Sign in
Get started
深度碎片
as simple as possible
Workspace
Fork
Published
Observable tutorials
By
深度碎片
Edited
Dec 9, 2019
Fork of
Views are Mutable Values
Observable tutorials
File Attachments
Slide
Views are Mutable Values
Generator Cells, Functions and Objects
Custom Generators
Notebook Visualizer
Hello and Welcome!
Synchronized Views
Introduction to Promises
Introduction to Views
Introduction to HTML
Introduction to Data
Introduction to Generators
Downloading and Embedding Notebooks
(2nd) Tutorial 1: Lunch calculator
(0th) Observable: The User Manual
(1st) Five-Minute Introduction
Insert cell
Insert cell
ordinary_viewof
=
md
`## simple viewof + slider`
Insert cell
viewof
x
=
html
`<input type=range>`
Insert cell
x
Insert cell
Insert cell
{
viewof
x
.
value
=
Math
.
random
(
)
*
100
;
viewof
x
.
dispatchEvent
(
new
CustomEvent
(
"input"
)
)
;
// without it x won't be updating
}
Insert cell
Insert cell
x
Insert cell
{
for
(
let
i
=
1
;
i
<=
50
;
++
i
)
{
viewof
x
.
value
=
i
;
viewof
x
.
dispatchEvent
(
new
CustomEvent
(
"input"
)
)
;
yield
;
}
}
Insert cell
Insert cell
x
// The same x as above (and below)!
Insert cell
{
const
form
=
html
`<form onsubmit="return false;">
<button name=inc>increment</button>
<button name=dec>decrement</button>
</form>`
;
form
.
inc
.
onclick
=
(
)
=>
{
++
viewof
x
.
value
;
viewof
x
.
dispatchEvent
(
new
CustomEvent
(
"input"
)
)
;
}
;
form
.
dec
.
onclick
=
(
)
=>
{
--
viewof
x
.
value
;
viewof
x
.
dispatchEvent
(
new
CustomEvent
(
"input"
)
)
;
}
;
return
form
;
}
Insert cell
Insert cell
{
const
input
=
html
`<input type=range min=0 max=100 step=1>`
;
input
.
oninput
=
(
)
=>
{
viewof
x
.
value
=
input
.
valueAsNumber
;
viewof
x
.
dispatchEvent
(
new
CustomEvent
(
"input"
)
)
;
}
;
const
update
=
(
)
=>
input
.
value
=
viewof
x
.
value
;
viewof
x
.
addEventListener
(
"input"
,
update
)
;
invalidation
.
then
(
(
)
=>
viewof
x
.
removeEventListener
(
"input"
,
update
)
)
;
return
update
(
)
,
input
;
}
Insert cell
x
// The same x as above (and below)!
Insert cell
{
const
input
=
html
`<input type=number min=0 max=100 step=1>`
;
input
.
oninput
=
(
)
=>
{
viewof
x
.
value
=
input
.
valueAsNumber
;
viewof
x
.
dispatchEvent
(
new
CustomEvent
(
"input"
)
)
;
}
;
const
update
=
(
)
=>
input
.
value
=
viewof
x
.
value
;
viewof
x
.
addEventListener
(
"input"
,
update
)
;
invalidation
.
then
(
(
)
=>
viewof
x
.
removeEventListener
(
"input"
,
update
)
)
;
return
update
(
)
,
input
;
}
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
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
ordinary_viewof
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
x
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
programmatic_random_control
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
generator_control
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
button_control
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
another_view_control
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML