Published
Edited
Jan 6, 2022
1 fork
11 stars
Also listed in…
Plot
Insert cell
Insert cell
chart = Generators.queue(
worker(
function P({ data }) {
return Plot.dot(data, {
x: "body_mass_g",
y: "species",
fill: "sex"
}).plot({ marginLeft: 100 }).outerHTML;
},
{ data: penguins },
preamble
)
)
.next()
.value.then((d) => svg`${d}`)
Insert cell
Insert cell
Generators.queue(
worker(
async function P({ url }) {
const data = await d3.csv(url, d3.autoType);
return {
svg: Plot.dot(data, {
x: "body_mass_g",
y: "species",
fill: "sex"
}).plot({ marginLeft: 100 }).outerHTML
};
},
{ url },
preamble
)
)
.next()
.value.then((d) => svg`${d.svg}`)
Insert cell
Insert cell
viewof data = Generators.queue(
worker(
async function P({ url }) {
const data = await d3.csv(url, d3.autoType);
return {
svg: Plot.dot(data, {
x: "body_mass_g",
y: "species",
fill: "sex"
}).plot({ marginLeft: 100 }).outerHTML,
data
};
},
{ url },
preamble
)
)
.next()
.value.then((d) => Object.assign(svg`${d.svg}`, { value: d.data }))
Insert cell
Inputs.table(data)
Insert cell
Insert cell
import { worker } from "@fil/worker"
Insert cell
preamble = `
importScripts("https://cdn.jsdelivr.net/npm/d3@7");
importScripts("https://cdn.jsdelivr.net/npm/@observablehq/plot@0.3.2");
importScripts("https://bundle.run/domino@2.1.6");
globalThis.document = domino.createDocument();
`
Insert cell
url = FileAttachment("penguins.csv").url()
Insert cell
penguins = FileAttachment("penguins.csv").csv({ typed: true })
Insert cell
Plot = "🤯" // a symbol to keep the Observable parser happy; we can leave it out and let it point to stdlib's version instead, but this clarifies that "Plot" in the worker is not this symbol
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more