Skip to content

Commit 23dcead

Browse files
committed
Add marimo notebook examples
1 parent 542d38b commit 23dcead

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

python/notebooks/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Grandscatter example notebooks
2+
3+
Running Jupyter notebooks in JupyterLab:
4+
5+
```sh
6+
uv run jupyter lab
7+
```
8+
9+
Running a marimo notebook locally (Python kernel):
10+
11+
```sh
12+
uv run marimo run example.py # app mode
13+
# or
14+
uv run marimo edit example.py # edit mode
15+
```
16+
17+
Building and serving a marimo WASM notebook (Pyodide kernel):
18+
19+
```sh
20+
uv run marimo export html-wasm --mode run -o html example_wasm.py # build for app mode
21+
# or
22+
uv run marimo export html-wasm --mode edit -o html example_wasm.py # build for edit mode
23+
# then
24+
uv run python -m http.server --directory html
25+
```

python/notebooks/example_wasm.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import marimo
2+
3+
__generated_with = "0.19.11"
4+
app = marimo.App()
5+
6+
7+
@app.cell
8+
def _():
9+
import os
10+
os.environ['ANYWIDGET_HMR'] = '1'
11+
return
12+
13+
14+
@app.cell
15+
def _():
16+
import marimo as mo
17+
18+
return (mo,)
19+
20+
21+
@app.cell
22+
async def _():
23+
import micropip
24+
await micropip.install("anywidget")
25+
await micropip.install("grandscatter", deps=False)
26+
27+
from grandscatter import Scatter
28+
29+
return (Scatter,)
30+
31+
32+
@app.cell
33+
def _():
34+
import pandas as pd
35+
import pyarrow as pa
36+
37+
return (pd,)
38+
39+
40+
@app.cell
41+
def _(pd):
42+
df = pd.read_feather("https://abdenlab.org/grandscatter/eigs.arrow")
43+
df
44+
return (df,)
45+
46+
47+
@app.cell
48+
def _(df):
49+
colors = dict(
50+
zip(
51+
df[["name", "color"]].drop_duplicates()["name"].tolist(),
52+
df[["name", "color"]].drop_duplicates()["color"].tolist()
53+
)
54+
)
55+
return (colors,)
56+
57+
58+
@app.cell
59+
def _(Scatter, colors, df, mo):
60+
widget = mo.ui.anywidget(
61+
Scatter(df, ["E1", "E2", "E3", "E4", "E5"], "name", colors, projection="perspective")
62+
)
63+
return (widget,)
64+
65+
66+
@app.cell
67+
def _(widget):
68+
widget
69+
return
70+
71+
72+
@app.cell
73+
def _(widget):
74+
widget.axis_length = 2
75+
return
76+
77+
78+
@app.cell
79+
def _(widget):
80+
widget.view_angle = 90
81+
return
82+
83+
84+
@app.cell
85+
def _(widget):
86+
widget.projection = "orthographic"
87+
return
88+
89+
90+
@app.cell
91+
def _(widget):
92+
widget.base_point_size = 4
93+
return
94+
95+
96+
@app.cell
97+
def _(df, widget):
98+
df.iloc[widget.selected_points]
99+
return
100+
101+
102+
if __name__ == "__main__":
103+
app.run()

0 commit comments

Comments
 (0)