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

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