Public
Edited
Nov 24, 2023
Insert cell
Insert cell
viewof view = embed(JSON.parse(chart_spec))
Insert cell
chart_spec = py`# start with a fake dependency on the libraries being installed:
# ${deps_installed}

# now the basic altair example:
import altair as alt
from vega_datasets import data
cars = data.cars.url

chart = alt.Chart(cars).mark_point().encode(
x='Horsepower:Q',
y='Miles_per_Gallon:Q',
color='Origin:N',
).interactive()

# this outputs Map, not Object:
# chart.to_dict()
# which, we could probably correct for directly
# for now, we'll take the hit of encoding and recoding it to JSON:
chart.to_json()`
Insert cell
deps_installed = py`import micropip
await micropip.install("altair")
await micropip.install("vega_datasets")`
Insert cell
py`import sys
sys.version`
Insert cell
import { py }
with { pyodide as pyodide }
from '@gnestor/pyodide@373'
Insert cell
embed = require("vega-embed@6")
Insert cell
pyodide = {
const pyodide = await require(`//cdn.jsdelivr.net/pyodide/${pyodide_version}/full/pyodide.js`);
return pyodide.loadPyodide({
indexURL: `https://cdn.jsdelivr.net/pyodide/${pyodide_version}/full/`
});
}
Insert cell
pyodide_version = "v0.21.0"
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