Skip to content

Commit a04c91c

Browse files
authored
Sandbox (#10)
* updated marimo files * build using the sandbox logic * build using the sandbox logic * do not explicitly install marimo * ignore __marimo__ folder * Update deploy.yml * Update deploy.yml
1 parent 79d1ad3 commit a04c91c

6 files changed

Lines changed: 74 additions & 56 deletions

File tree

.github/scripts/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def export_html_wasm(notebook_path: str, output_dir: str, as_app: bool = False)
3939
output_path: str = notebook_path.replace(".py", ".html")
4040

4141
# Base command for marimo export
42-
cmd: List[str] = ["marimo", "export", "html-wasm"]
42+
cmd: List[str] = ["uvx", "marimo", "export", "html-wasm", "--sandbox"]
4343

4444
# Configure export mode based on whether it's an app or a notebook
4545
if as_app:

.github/workflows/deploy.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,24 @@ jobs:
3030
- name: 🚀 Install uv
3131
uses: astral-sh/setup-uv@v6
3232

33-
# Set up Python environment
34-
- name: 🐍 Set up Python
35-
uses: actions/setup-python@v5
36-
with:
37-
python-version: 3.12 # Use Python 3.12 for the build
33+
# Set up Python environment (obsolete as done by the setup-uv step)?
34+
#- name: 🐍 Set up Python
35+
# uses: actions/setup-python@v5
36+
# with:
37+
# python-version: 3.12 # Use Python 3.12 for the build
38+
3839

3940
# Install marimo and other required dependencies
40-
- name: 📦 Install dependencies
41-
run: |
42-
uv pip install marimo
41+
#- name: 📦 Install dependencies
42+
# run: |
43+
# uv pip install marimo
4344

4445
# Run the build script to export notebooks to WebAssembly
4546
- name: 🛠️ Export notebooks
4647
run: |
4748
python .github/scripts/build.py # This script exports all notebooks to the _site directory
48-
49+
tree _site # Display the exported files
50+
4951
# Upload the generated site as an artifact for the deploy job
5052
- name: 📤 Upload artifact
5153
uses: actions/upload-pages-artifact@v3

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
_site/
2+
__marimo__
23

34
# Byte-compiled / optimized / DLL files
45
__pycache__/

apps/charts.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1+
# /// script
2+
# requires-python = ">=3.12"
3+
# dependencies = [
4+
# "marimo==0.13.15",
5+
# "altair==4.2.0",
6+
# "pandas==2.3.0",
7+
# "numpy==2.3.0"
8+
# ]
9+
# ///
110
import marimo
211

312
__generated_with = "0.10.9"
413
app = marimo.App(width="medium")
514

6-
7-
@app.cell
8-
def _():
15+
with app.setup:
916
import numpy as np
1017
import altair as alt
1118
import pandas as pd
1219
import marimo as mo
13-
return alt, mo, np, pd
1420

1521

1622
@app.cell
17-
def _(mo):
23+
def _():
1824
mo.md(
1925
"""
2026
# Interactive Data Visualization
@@ -29,7 +35,7 @@ def _(mo):
2935

3036

3137
@app.cell
32-
def _(alt, mo, np, pd):
38+
def _():
3339
# Create sample data
3440
data = pd.DataFrame({"x": np.arange(100), "y": np.random.normal(0, 1, 100)})
3541

@@ -43,7 +49,7 @@ def _(alt, mo, np, pd):
4349
)
4450
)
4551
chart
46-
return chart, data
52+
return chart
4753

4854

4955
@app.cell

notebooks/fibonacci.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
# /// script
2+
# requires-python = ">=3.12"
3+
# dependencies = [
4+
# "marimo==0.13.15",
5+
# ]
6+
# ///
17
import marimo
28

39
__generated_with = "0.10.6"
410
app = marimo.App()
511

6-
12+
with app.setup:
13+
import marimo as mo
14+
715
@app.cell
8-
def _(mo):
16+
def _():
917
mo.md(
1018
r"""
1119
# Fibonacci Calculator
@@ -17,37 +25,25 @@ def _(mo):
1725

1826

1927
@app.cell
20-
def _(mo):
28+
def _():
2129
# Create an interactive slider
2230
n = mo.ui.slider(1, 100, value=50, label="Number of Fibonacci numbers")
2331
n
24-
return (n,)
32+
return n
2533

2634

2735
@app.cell
28-
def _(fibonacci, mo, n):
36+
def _(n):
2937
fib = fibonacci(n.value)
3038
mo.md(", ".join([str(f) for f in fib]))
31-
return (fib,)
32-
33-
34-
@app.cell
35-
def _():
36-
# Generate Fibonacci sequence
37-
def fibonacci(n):
38-
sequence = [0, 1]
39-
for i in range(2, n):
40-
sequence.append(sequence[i - 1] + sequence[i - 2])
41-
return sequence
42-
return (fibonacci,)
43-
44-
45-
@app.cell
46-
def _():
47-
import numpy as np
48-
import marimo as mo
49-
return mo, np
50-
39+
40+
@app.function
41+
def fibonacci(n):
42+
sequence = [0, 1]
43+
for i in range(2, n):
44+
sequence.append(sequence[i - 1] + sequence[i - 2])
45+
return sequence
46+
5147

5248
if __name__ == "__main__":
5349
app.run()

notebooks/penguins.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1+
# /// script
2+
# requires-python = ">=3.12"
3+
# dependencies = [
4+
# "marimo==0.13.15",
5+
# "polars==1.30.0",
6+
# "altair==4.2.0",
7+
# "pandas==2.3.0",
8+
# ]
9+
# ///
110
import marimo
211

3-
__generated_with = "0.10.9"
12+
__generated_with = "0.13.5"
413
app = marimo.App(width="medium")
514

6-
7-
@app.cell
8-
def _():
9-
import polars as pl
15+
with app.setup:
1016
import marimo as mo
17+
import polars as pl
1118
import altair as alt
12-
return alt, mo, pl
19+
import pandas as pd
1320

21+
file = mo.notebook_location() / "public" / "penguins.csv"
1422

1523
@app.cell(hide_code=True)
16-
def _(mo):
24+
def _():
1725
mo.md(
1826
"""
1927
# Palmer Penguins Analysis
@@ -25,15 +33,20 @@ def _(mo):
2533

2634

2735
@app.cell
28-
def _(mo, pl):
36+
def _():
2937
# Read the penguins dataset
30-
df = pl.read_csv(str(mo.notebook_location() / "public" / "penguins.csv"))
38+
df = pl.read_csv(str(file))
3139
df.head()
3240
return (df,)
3341

42+
@app.cell
43+
def _():
44+
# Try to avoid reading the file with pandas
45+
_df = pd.read_csv(str(file))
46+
return
3447

3548
@app.cell
36-
def _(df, mo):
49+
def _(df):
3750
# Basic statistics
3851
mo.md(f"""
3952
### Dataset Overview
@@ -49,13 +62,13 @@ def _(df, mo):
4962

5063

5164
@app.cell(hide_code=True)
52-
def _(mo):
65+
def _():
5366
mo.md(r"""### Species Distribution""")
5467
return
5568

5669

5770
@app.cell
58-
def _(alt, df, mo):
71+
def _(df):
5972
# Create species distribution chart
6073
species_chart = mo.ui.altair_chart(
6174
alt.Chart(df)
@@ -70,13 +83,13 @@ def _(alt, df, mo):
7083

7184

7285
@app.cell(hide_code=True)
73-
def _(mo):
86+
def _():
7487
mo.md(r"""### Bill Dimensions Analysis""")
7588
return
7689

7790

7891
@app.cell
79-
def _(alt, df, mo):
92+
def _(df):
8093
# Scatter plot of bill dimensions
8194
scatter = mo.ui.altair_chart(
8295
alt.Chart(df)

0 commit comments

Comments
 (0)