diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 8d00b7e..ceaa261 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -37,7 +37,7 @@ jobs: - name: ๐Ÿ“ค Upload artifact uses: actions/upload-pages-artifact@v3 with: - path: public + path: _site deploy: needs: build diff --git a/.gitignore b/.gitignore index ff4426d..b458785 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +_site/ + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/README.md b/README.md index e64b085..80ab442 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ This template repository demonstrates how to export [marimo](https://marimo.io) - `apps/charts.py`: Interactive data visualization with Altair - `notebooks/fibonacci.py`: Interactive Fibonacci sequence calculator +- `notebooks/penguins.py`: Interactive data analysis with Polars and marimo ## ๐Ÿš€ Usage @@ -16,3 +17,36 @@ This template repository demonstrates how to export [marimo](https://marimo.io) 3. Push to main branch 4. Go to repository **Settings > Pages** and change the "Source" dropdown to "GitHub Actions" 5. GitHub Actions will automatically build and deploy to Pages + +## Including data or assets + +To include data or assets in your notebooks, add them to the `public/` directory. + +For example, the `apps/charts.py` notebook loads an image asset from the `public/` directory. + +```markdown + +``` + +And the `notebooks/penguins.py` notebook loads a CSV dataset from the `public/` directory. + +```python +import polars as pl +df = pl.read_csv(mo.notebook_location() / "public" / "penguins.csv") +``` + +## ๐Ÿงช Testing + +To test the export process, run `scripts/build.py` from the root directory. + +```bash +python scripts/build.py +``` + +This will export all notebooks in a folder called `_site/` in the root directory. Then to serve the site, run: + +```bash +python -m http.server -d _site +``` + +This will serve the site at `http://localhost:8000`. diff --git a/apps/charts.py b/apps/charts.py index 235971b..e9d6a88 100644 --- a/apps/charts.py +++ b/apps/charts.py @@ -1,6 +1,6 @@ import marimo -__generated_with = "0.10.6" +__generated_with = "0.10.9" app = marimo.App(width="medium") @@ -19,6 +19,8 @@ def _(mo): """ # Interactive Data Visualization + + This notebook demonstrates a simple interactive visualization using Altair. Try selecting the points! """ diff --git a/notebooks/penguins.py b/notebooks/penguins.py new file mode 100644 index 0000000..42e5dc2 --- /dev/null +++ b/notebooks/penguins.py @@ -0,0 +1,99 @@ +import marimo + +__generated_with = "0.10.9" +app = marimo.App(width="medium") + + +@app.cell +def _(): + import polars as pl + import marimo as mo + import altair as alt + return alt, mo, pl + + +@app.cell(hide_code=True) +def _(mo): + mo.md( + """ + # Palmer Penguins Analysis + + Analyzing the Palmer Penguins dataset using Polars and marimo. + """ + ) + return + + +@app.cell +def _(mo, pl): + # Read the penguins dataset + df = pl.read_csv(mo.notebook_location() / "public" / "penguins.csv") + df.head() + return (df,) + + +@app.cell +def _(df, mo): + # Basic statistics + mo.md(f""" + ### Dataset Overview + + - Total records: {df.height} + - Columns: {', '.join(df.columns)} + + ### Summary Statistics + + {mo.as_html(df.describe())} + """) + return + + +@app.cell(hide_code=True) +def _(mo): + mo.md(r"""### Species Distribution""") + return + + +@app.cell +def _(alt, df, mo): + # Create species distribution chart + species_chart = mo.ui.altair_chart( + alt.Chart(df) + .mark_bar() + .encode(x="species", y="count()", color="species") + .properties(title="Distribution of Penguin Species"), + chart_selection=None, + ) + + species_chart + return (species_chart,) + + +@app.cell(hide_code=True) +def _(mo): + mo.md(r"""### Bill Dimensions Analysis""") + return + + +@app.cell +def _(alt, df, mo): + # Scatter plot of bill dimensions + scatter = mo.ui.altair_chart( + alt.Chart(df) + .mark_point() + .encode( + x="bill_length_mm", + y="bill_depth_mm", + color="species", + tooltip=["species", "bill_length_mm", "bill_depth_mm"], + ) + .properties(title="Bill Length vs Depth by Species"), + chart_selection=None, + ) + + scatter + return (scatter,) + + +if __name__ == "__main__": + app.run() diff --git a/scripts/build.py b/scripts/build.py index 5d0ecfe..905e2a7 100755 --- a/scripts/build.py +++ b/scripts/build.py @@ -88,7 +88,7 @@ def generate_index(all_notebooks: List[str], output_dir: str) -> None: def main() -> None: parser = argparse.ArgumentParser(description="Build marimo notebooks") parser.add_argument( - "--output-dir", default="public", help="Output directory for built files" + "--output-dir", default="_site", help="Output directory for built files" ) args = parser.parse_args()