Published
Edited
Sep 13, 2019
Insert cell
md`# Notes

Blocks are like functions, but they run immediately and don’t have parameters. Just like before, when you move the slider, the value of total is automatically recomputed




`
Insert cell

d3 = require('d3@5') // will make all of d3.js available
Insert cell
ss = require('simple-statistics') // can do simple statistics with this
Insert cell
prods = ss.sum([1,2,3]) * ss.min([4,7,9]);

Insert cell
md`${prods}`
Insert cell
state = {
let x = 5;
let y = "";
if (x > 1) {
y = "x is greater than 1"
}
return y;
}
Insert cell
cel2fahr =
((f - 32) / 9 ) * 5;
Insert cell
f = 32
Insert cell
someblock = {
return {
x : ss.sum([1,2,3]),
y : ss.mean([1,2,3])
}
}
// You can create a block and a cell as a literal object this way
Insert cell
someblock.x / someblock.y
Insert cell
function cels2fahr (cels){
let fahr = (cels / 5) * 9 + 32
return fahr;
}
// you can create functions and call the function everywhere
Insert cell
cels2fahr(0)
Insert cell
dict = ({
x : 1,
y : 2
})
// create an object literal, you can even create small data sets this way
Insert cell
dict.x + dict.y // then do whatever you want to do in another cell
Insert cell
mydata = ({
x : [1,2,3,4,5,6],
y : [4, 6, 7, 9, 12, 34]
})
Insert cell
mydata.x
Insert cell
plt = require("https://cdn.plot.ly/plotly-latest.min.js")
Insert cell
vgl = require('@observablehq/vega-lite')
Insert cell
mydata2 = d3.csvParse(`x,y
1,3
2,5
3,7
4,8`)
Insert cell
vgl({
data: {values: mydata2},
mark: 'point',
encoding: {
x: {field: 'x', type: 'quantitative'},
y: {field: 'y', type: 'quantitative'}
}
})
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