Public
Edited
Jun 5, 2023
Fork of Pyodide demo
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
py`import sys
sys.version`
Insert cell
Insert cell
py`from js import document
document.body.children`
Insert cell
Insert cell
a = py`from random import sample
sample(range(0, 5), 5)`
Insert cell
b = py`from random import sample
sample(range(0, 5), 5)`
Insert cell
c = py`[x * y for x, y in zip(${a}, ${b})]`
Insert cell
Insert cell
np = py`import numpy as np
np`
Insert cell
x = np.linspace(0, 2.0 * np.pi, 100)
Insert cell
x.toJs()
Insert cell
y = np.sin(x)
Insert cell
y.toJs()
Insert cell
Insert cell
{
const div = html`<div id="plotly-div" />`;
const data = [{ y: y.toJs(), x: x.toJs() }];
Plotly.plot(div, data, { width });
return div;
}
Insert cell
Insert cell
plt = py`from matplotlib import pyplot as plt
import types
import io
import base64
from js import document

def show(self):
buf = io.BytesIO()
self.savefig(buf, format='png')
buf.seek(0)
img_str = 'data:image/png;base64,' + base64.b64encode(buf.read()).decode('UTF-8')
el = document.createElement('img')
el.src = img_str
return el

plt._show = types.MethodType(plt.show, plt)
plt.show = types.MethodType(show, plt)

plt`
Insert cell
{
plt.figure();
plt.plot(x, y);
return plt.show();
}
Insert cell
Insert cell
pd = py`import pandas as pd
pd`
Insert cell
df = pd.read_csv(
pyodide.pyodide_py.open_url(
"https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv"
)
)
Insert cell
df.head().to_string()
Insert cell
table(
df
.to_dict('records')
.toJs()
.map(Object.fromEntries)
)
Insert cell
Insert cell
button({
label: 'import antigravity',
onClick: async () => {
await py`import antigravity`;
}
})
Insert cell
Insert cell
py`from js import fetch

resp = await fetch('https://jsonplaceholder.typicode.com/todos')
await resp.json()`
Insert cell
Insert cell
import { py, pyodide } from '@gnestor/pyodide'
Insert cell
Plotly = require('//cdn.plot.ly/plotly-latest.min.js')
Insert cell
import { table } from '@gnestor/table'
Insert cell
import { renderedButton as button } from '@gnestor/react-components'
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