Skip to content

Commit

Permalink
add script/ipynb/html
Browse files Browse the repository at this point in the history
  • Loading branch information
mscolnick committed Dec 4, 2024
1 parent 24b15d9 commit 854e158
Show file tree
Hide file tree
Showing 40 changed files with 3,884 additions and 8 deletions.
38 changes: 36 additions & 2 deletions .github/workflows/export-notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ on:
repository_dispatch:
types: [marimo-release]

# Trigger on push to main
# Trigger on push to main, but ignore if in generated files
push:
branches: [main]
paths-ignore:
- 'generated/**'
- 'public/**'

# Trigger nightly
schedule:
Expand All @@ -17,7 +20,10 @@ on:
workflow_dispatch: {}

permissions:
pull-requests: write
contents: write
pages: write
id-token: write

env:
UV_SYSTEM_PYTHON: 1
Expand All @@ -40,6 +46,7 @@ jobs:
- name: 📦 Install marimo
run: |
uv pip install marimo
uv pip install nbformat polars altair vega_datasets matplotlib pandas
- name: 📂 Clone marimo examples
run: |
Expand Down Expand Up @@ -71,4 +78,31 @@ jobs:
automated
assignees: |
mscolnick
add-paths: 'generated/*'
add-paths: |
generated/*
public/*
deploy:
needs: export-notebooks
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: 📥 Download artifact
uses: actions/download-artifact@v4
with:
name: github-pages

- name: 📦 Setup Pages
uses: actions/configure-pages@v4

- name: 🚀 Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: public

- name: 🌐 Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Automated CI pipeline for validating and exporting [marimo](https://github.com/m

- Automatically exports whitelisted marimo notebooks:
- to markdown
- (soon) to HTML
- (soon) to ipynb
- (soon) to script
- to HTML
- to ipynb
- to script
- Triggers on:
- (todo) New marimo releases
- Pushes to main from this repo
Expand Down
178 changes: 178 additions & 0 deletions generated/examples/ui/arrays_and_dicts.py.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "Hbol",
"metadata": {},
"source": [
"# Arrays and Dictionaries"
]
},
{
"cell_type": "markdown",
"id": "MJUe",
"metadata": {},
"source": [
"Use `mo.ui.array` and `mo.ui.dictionary` to create UI elements that wrap\n",
"other elements.\n",
"\n",
"Because UI elements must be assigned to global variables,\n",
"these functions are required when the set of elements to create is not\n",
"known until runtime."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "vblA",
"metadata": {},
"outputs": [],
"source": [
"create = mo.ui.button(label=\"Create new collections\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bkHC",
"metadata": {},
"outputs": [],
"source": [
"create.center()"
]
},
{
"cell_type": "markdown",
"id": "lEQa",
"metadata": {},
"source": [
"UI Elements ..."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "PKri",
"metadata": {},
"outputs": [],
"source": [
"create\n",
"\n",
"array = mo.ui.array(\n",
" [mo.ui.text()]\n",
" + [mo.ui.slider(1, 10) for _ in range(0, random.randint(2, 5))],\n",
")\n",
"dictionary = mo.ui.dictionary(\n",
" {str(i): mo.ui.slider(1, 10) for i in range(0, random.randint(2, 5))}\n",
")\n",
"\n",
"mo.hstack([array, dictionary], justify=\"space-around\")"
]
},
{
"cell_type": "markdown",
"id": "Xref",
"metadata": {},
"source": [
"... and their values"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "SFPL",
"metadata": {},
"outputs": [],
"source": [
"mo.hstack([array.value, dictionary.value], justify=\"space-around\")"
]
},
{
"cell_type": "markdown",
"id": "BYtC",
"metadata": {},
"source": [
"Key difference between marimo dict and standard python dict:\n",
"\n",
"The main reason to use `mo.ui.dictionary` is for reactive execution — when you interact with an element in a `mo.ui.dictionary`, all cells that reference the `mo.ui.dictionary` run automatically, just like all other ui elements. When you use a regular dictionary, you don't get this reactivity."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "RGSE",
"metadata": {},
"outputs": [],
"source": [
"create\n",
"\n",
"slider = mo.ui.slider(1, 10, show_value=True)\n",
"text = mo.ui.text()\n",
"date = mo.ui.date()\n",
"\n",
"mo_d = mo.ui.dictionary(\n",
" {\n",
" \"slider\": slider,\n",
" \"text\": text,\n",
" \"date\": date,\n",
" }\n",
")\n",
"\n",
"py_d = {\n",
" \"slider\": slider,\n",
" \"text\": text,\n",
" \"date\": date,\n",
"}\n",
"\n",
"mo.hstack(\n",
" [\n",
" mo.vstack([\"marimo dict\", mo_d]),\n",
" mo.vstack([\"original elements\", mo.vstack([slider, text, date])]),\n",
" mo.vstack([\"python dict\", py_d]),\n",
" ],\n",
" justify=\"space-around\",\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "Kclp",
"metadata": {},
"outputs": [],
"source": [
"mo_d_ref = {k: mo_d[k].value for k in mo_d.value.keys()}\n",
"py_d_ref = {k: py_d[k].value for k in py_d.keys()}\n",
"mo.hstack(\n",
" [\n",
" mo.vstack([\"reference of marimo dict\", mo_d_ref]),\n",
" mo.vstack([\"reference of python dict\", py_d_ref]),\n",
" ],\n",
" justify=\"space-around\",\n",
")"
]
},
{
"cell_type": "markdown",
"id": "emfo",
"metadata": {},
"source": [
"Notice that when you interact with the UI elements in the marimo dict, the reference of marimo dict updates automatically. However, when you interact with the elements in the python dict, you need to manually re-run the cell to see the updated values."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "Hstk",
"metadata": {},
"outputs": [],
"source": [
"import marimo as mo\n",
"import random"
]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
102 changes: 102 additions & 0 deletions generated/examples/ui/arrays_and_dicts.script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

__generated_with = "0.9.30"

# %%
import marimo as mo
import random

# %%
mo.md(
"""
Use `mo.ui.array` and `mo.ui.dictionary` to create UI elements that wrap
other elements.
Because UI elements must be assigned to global variables,
these functions are required when the set of elements to create is not
known until runtime.
"""
)

# %%
mo.md(
r"""
Key difference between marimo dict and standard python dict:
The main reason to use `mo.ui.dictionary` is for reactive execution — when you interact with an element in a `mo.ui.dictionary`, all cells that reference the `mo.ui.dictionary` run automatically, just like all other ui elements. When you use a regular dictionary, you don't get this reactivity.
"""
)

# %%
create = mo.ui.button(label="Create new collections")

# %%
mo.md("""UI Elements ...""")

# %%
mo.md(r"""Notice that when you interact with the UI elements in the marimo dict, the reference of marimo dict updates automatically. However, when you interact with the elements in the python dict, you need to manually re-run the cell to see the updated values.""")

# %%
mo.md("""... and their values""")

# %%
mo.md("""# Arrays and Dictionaries""")

# %%
create.center()

# %%
create

slider = mo.ui.slider(1, 10, show_value=True)
text = mo.ui.text()
date = mo.ui.date()

mo_d = mo.ui.dictionary(
{
"slider": slider,
"text": text,
"date": date,
}
)

py_d = {
"slider": slider,
"text": text,
"date": date,
}

mo.hstack(
[
mo.vstack(["marimo dict", mo_d]),
mo.vstack(["original elements", mo.vstack([slider, text, date])]),
mo.vstack(["python dict", py_d]),
],
justify="space-around",
)

# %%
create

array = mo.ui.array(
[mo.ui.text()]
+ [mo.ui.slider(1, 10) for _ in range(0, random.randint(2, 5))],
)
dictionary = mo.ui.dictionary(
{str(i): mo.ui.slider(1, 10) for i in range(0, random.randint(2, 5))}
)

mo.hstack([array, dictionary], justify="space-around")

# %%
mo_d_ref = {k: mo_d[k].value for k in mo_d.value.keys()}
py_d_ref = {k: py_d[k].value for k in py_d.keys()}
mo.hstack(
[
mo.vstack(["reference of marimo dict", mo_d_ref]),
mo.vstack(["reference of python dict", py_d_ref]),
],
justify="space-around",
)

# %%
mo.hstack([array.value, dictionary.value], justify="space-around")
Loading

0 comments on commit 854e158

Please sign in to comment.