Public
Edited
Mar 18, 2023
Insert cell
Insert cell
Insert cell
Insert cell
c2 = operation(88, 11, subtract)
Insert cell
Insert cell
b = 10
Insert cell
arr = ["tom turbo", "fritz phantom", "anna"]
Insert cell
myObj = ({name: 'Patrick', age: 30})
Insert cell
function add(a,b) {
return a+b;
}
Insert cell
add(1, 3)
Insert cell
function subtract(a, b) {
return a - b;
}
Insert cell
function operation(a,b,op) {
return op(a,b)
}
Insert cell
c1 = operation(a, b, subtract)
Insert cell
hello = new Promise((resolve) => setTimeout(() => resolve("Hi"), 2000))
Insert cell
Insert cell
{
let a = 5;
let string = "";
for (let i = 0; i < a; i++) {
string += "a";
}
return string;
}


Insert cell
Insert cell
d3 = require("d3")
Insert cell
Insert cell
html`<h4>HTML</h4>`
Insert cell
html`<p>My favorite color is <span style="color:${color}">${color}</span></p>`
Insert cell
color = "purple"
Insert cell
md`My result for c1: ${c1}`
Insert cell
Insert cell
html`<h4 style="color:${myColor}">Hello ${yourName}</h4>`
Insert cell
myName = "Klaus"
Insert cell
Insert cell
viewof yourName = html`<input type="text">`
Insert cell
viewof yourColor = html`<input type="color">`
Insert cell
Insert cell
viewof myColor = Inputs.color({ label: "Favorite color", value: "#4682b4" })
Insert cell
viewof radios = Inputs.radio(["A", "B"], {label: "Select one"})
Insert cell
md`My selection is: ${radios}`
Insert cell
Insert cell
Insert cell
import { chart as chartMoon, viewof year } from "@mbostock/phases-of-the-moon"
Insert cell
moonYear = viewof year
Insert cell
moons = chartMoon
Insert cell
Insert cell
import { chart } with { myData as alphabet } from "@d3/bar-chart"
Insert cell
chart
Insert cell
myData = [
{ letter: "Thumb", frequency: 0.6 },
{ letter: "Index", frequency: 0.85 },
{ letter: "Middle", frequency: 1 },
{ letter: "Ring", frequency: 0.9 },
{ letter: "Pinky", frequency: 0.75 }
]
Insert cell
Insert cell
Insert cell
movie = [
{ title: "Deadpool", year: 2016 },
{ title: "Jurassic Park", year: 1993 },
{ title: "Star Wars", year: 1977 },
{ title: "The Godfather", year: 1972 },
{ title: "Snow White and the Seven Dwarfs", year: 1927 }
]
Insert cell
Insert cell
dataIris = FileAttachment("iris.csv").csv()
Insert cell
dataPokemon = FileAttachment("pokemon.csv").csv()
Insert cell
jsonIris = FileAttachment("iris.json").json()
Insert cell
Insert cell
Insert cell
Insert cell
import { alphabet } from "@d3/bar-chart"
Insert cell
alphabet
Insert cell
Insert cell
Insert cell
url = "https://data.sfgov.org/resource/xdgd-c79v.json"
Insert cell
response = fetch(url)
Insert cell
Insert cell
// Bad to use .json() on a fetch respose can only be executed once.
// response.json()
Insert cell
Insert cell
jsonData = (await fetch(url)).json()
Insert cell
Insert cell
jsonDataD3 = d3.json(url)
Insert cell
Insert cell
weatherData = d3.csv(
"https://raw.githubusercontent.com/vega/vega-datasets/master/data/weather.csv"
)
Insert cell
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