Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

docs: convert doc example to use wasm (#859)

Myles Scolnick3ed9bf79634c
diff --git a/docs/_static/css/custom.css b/docs/_static/css/custom.css
index dba53fbbea..4698ef150d 100644
--- a/docs/_static/css/custom.css
+++ b/docs/_static/css/custom.css
@@ -38,6 +38,10 @@ iframe.demo {
border-radius: 5px;
}
+.autosummary > table {
+ width: 98%;
+}
+
iframe.demo.medium {
height: 400px;
}
diff --git a/docs/api/diagrams.md b/docs/api/diagrams.md
index 03d292ef78..a8445847f4 100644
--- a/docs/api/diagrams.md
+++ b/docs/api/diagrams.md
@@ -1,6 +1,14 @@
# Diagrams
-<!-- <iframe class="demo large" src="https://components.marimo.io/?component=mermaid" frameborder="no"></iframe> -->
+```{eval-rst}
+.. marimo-embed::
+ :size: medium
+
+ @app.cell
+ def __():
+ mo.mermaid("graph TD\n A[Christmas] -->|Get money| B(Go shopping)\n B --> C{Let me think}\n C -->|One| D[Laptop]\n C -->|Two| E[iPhone]\n C -->|Three| F[Car]")
+ return
+```
## Mermaid diagrams
@@ -8,10 +16,18 @@
.. autofunction:: marimo.mermaid
```
-
## Statistic cards
-<iframe class="demo medium" src="https://components.marimo.io/?component=stat" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ mo.hstack([
+ mo.stat(value="100.54", label="Open price", caption="2.4", direction="increase", bordered=True),
+ mo.stat(value="100.54", label="Close price", caption="2.4", direction="decrease", bordered=True),
+ ])
+ return
+```
```{eval-rst}
.. autofunction:: marimo.stat
diff --git a/docs/api/inputs/array.md b/docs/api/inputs/array.md
index b626d5ae53..e3cf6bec4d 100644
--- a/docs/api/inputs/array.md
+++ b/docs/api/inputs/array.md
@@ -1,6 +1,18 @@
# Array
-<iframe class="demo medium" src="https://components.marimo.io/?component=array" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ wish = mo.ui.text(placeholder="Wish")
+ wishes = mo.ui.array([wish] * 3, label="Three wishes")
+ return
+
+ @app.cell
+ def __():
+ mo.hstack([wishes, wishes.value], justify="space-between")
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.array
diff --git a/docs/api/inputs/batch.md b/docs/api/inputs/batch.md
index f19e6acf02..9152a66b3d 100644
--- a/docs/api/inputs/batch.md
+++ b/docs/api/inputs/batch.md
@@ -1,6 +1,21 @@
# Batch
-<iframe class="demo medium" src="https://components.marimo.io/?component=batch" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ el = mo.md("{start} → {end}").batch(
+ start=mo.ui.date(label="Start Date"),
+ end=mo.ui.date(label="End Date")
+ )
+ el
+ return
+
+ @app.cell
+ def __():
+ el.value
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.batch
diff --git a/docs/api/inputs/button.md b/docs/api/inputs/button.md
index b263884cfa..5029d17194 100644
--- a/docs/api/inputs/button.md
+++ b/docs/api/inputs/button.md
@@ -1,6 +1,12 @@
# Button
-<iframe class="demo" src="https://components.marimo.io/?component=button" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ mo.ui.button(label="Click me")
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.button
diff --git a/docs/api/inputs/checkbox.md b/docs/api/inputs/checkbox.md
index 4d1b07a0ed..978181663a 100644
--- a/docs/api/inputs/checkbox.md
+++ b/docs/api/inputs/checkbox.md
@@ -1,6 +1,17 @@
# Checkbox
-<iframe class="demo" src="https://components.marimo.io/?component=checkbox" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ checkbox = mo.ui.checkbox(label="check me")
+ return
+
+ @app.cell
+ def __():
+ mo.hstack([checkbox, mo.md(f"Has value: {checkbox.value}")])
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.checkbox
diff --git a/docs/api/inputs/code_editor.md b/docs/api/inputs/code_editor.md
index 29ce139433..dc8e1584db 100644
--- a/docs/api/inputs/code_editor.md
+++ b/docs/api/inputs/code_editor.md
@@ -1,6 +1,12 @@
# Code Editor
-<!-- <iframe class="demo" src="https://components.marimo.io/?component=code_editor" frameborder="no"></iframe> -->
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ mo.ui.code_editor(label="Code Editor", language="python")
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.code_editor
diff --git a/docs/api/inputs/data_explorer.md b/docs/api/inputs/data_explorer.md
index a0696123c9..2412996e47 100644
--- a/docs/api/inputs/data_explorer.md
+++ b/docs/api/inputs/data_explorer.md
@@ -9,7 +9,20 @@ In order to use the dataframe UI element, you must have the `pandas` package ins
You can install it with `pip install pandas`.
```
-<!-- <iframe class="demo large" src="https://components.marimo.io/?component=data_explorer" frameborder="no"></iframe> -->
+```{eval-rst}
+.. marimo-embed::
+ :size: large
+ :app_width: full
+
+ @app.cell
+ def __():
+ import pandas as pd
+ import pyodide
+ csv = pyodide.http.open_url("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv")
+ df = pd.read_csv(csv)
+ mo.ui.data_explorer(df)
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.data_explorer
diff --git a/docs/api/inputs/dataframe.md b/docs/api/inputs/dataframe.md
index e27430049a..f2ac419ccc 100644
--- a/docs/api/inputs/dataframe.md
+++ b/docs/api/inputs/dataframe.md
@@ -18,7 +18,20 @@ Supported transforms are:
- Group By
- Aggregate
-<!-- <iframe class="demo large" src="https://components.marimo.io/?component=dataframe" frameborder="no"></iframe> -->
+```{eval-rst}
+.. marimo-embed::
+ :size: large
+ :app_width: full
+
+ @app.cell
+ def __():
+ import pandas as pd
+ import pyodide
+ csv = pyodide.http.open_url("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv")
+ df = pd.read_csv(csv)
+ mo.ui.dataframe(df)
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.dataframe
diff --git a/docs/api/inputs/date.md b/docs/api/inputs/date.md
index ec72dc0042..b0e9fd82e0 100644
--- a/docs/api/inputs/date.md
+++ b/docs/api/inputs/date.md
@@ -1,6 +1,17 @@
# Date
-<iframe class="demo" src="https://components.marimo.io/?component=date" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ date = mo.ui.date(label="Start Date")
+ return
+
+ @app.cell
+ def __():
+ mo.hstack([date, mo.md(f"Has value: {date.value}")])
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.date
diff --git a/docs/api/inputs/dictionary.md b/docs/api/inputs/dictionary.md
index bfbfbf61e2..a88a188754 100644
--- a/docs/api/inputs/dictionary.md
+++ b/docs/api/inputs/dictionary.md
@@ -1,6 +1,29 @@
# Dictionary
-<iframe class="demo medium" src="https://components.marimo.io/?component=dictionary" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ first_name = mo.ui.text(placeholder="First name")
+ last_name = mo.ui.text(placeholder="Last name")
+ email = mo.ui.text(placeholder="Email", kind="email")
+
+ dictionary = mo.ui.dictionary(
+ {
+ "First name": first_name,
+ "Last name": last_name,
+ "Email": email,
+ }
+ )
+ return
+ @app.cell
+ def __():
+ mo.hstack(
+ [dictionary, dictionary.value],
+ justify="space-between"
+ )
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.dictionary
diff --git a/docs/api/inputs/dropdown.md b/docs/api/inputs/dropdown.md
index 9271d4e751..bcff0f2ac7 100644
--- a/docs/api/inputs/dropdown.md
+++ b/docs/api/inputs/dropdown.md
@@ -1,6 +1,18 @@
# Dropdown
-<iframe class="demo" src="https://components.marimo.io/?component=dropdown" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ options = ["Apples", "Oranges", "Pears"]
+ dropdown = mo.ui.dropdown(options=options)
+ return
+
+ @app.cell
+ def __():
+ mo.hstack([dropdown, mo.md(f"Has value: {dropdown.value}")])
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.dropdown
diff --git a/docs/api/inputs/file.md b/docs/api/inputs/file.md
index da224c6a0b..5e37ec5950 100644
--- a/docs/api/inputs/file.md
+++ b/docs/api/inputs/file.md
@@ -1,6 +1,12 @@
# File
-<iframe class="demo medium" src="https://components.marimo.io/?component=file" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ mo.vstack([mo.ui.file(kind="button"), mo.ui.file(kind="area")])
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.file
diff --git a/docs/api/inputs/form.md b/docs/api/inputs/form.md
index 42c8c0ee1b..f1ff63a96c 100644
--- a/docs/api/inputs/form.md
+++ b/docs/api/inputs/form.md
@@ -1,6 +1,19 @@
# Form
-<iframe class="demo large" src="https://components.marimo.io/?component=form" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ :size: medium
+
+ @app.cell
+ def __():
+ form = mo.ui.text_area(placeholder="...").form()
+ return
+
+ @app.cell
+ def __():
+ mo.vstack([form, mo.md(f"Has value: {form.value}")])
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.form
diff --git a/docs/api/inputs/index.md b/docs/api/inputs/index.md
index 981b50398c..5be5ec8911 100644
--- a/docs/api/inputs/index.md
+++ b/docs/api/inputs/index.md
@@ -9,7 +9,6 @@
batch
button
checkbox
- chart
code_editor
dataframe
data_explorer
@@ -42,7 +41,6 @@ powerful notebooks and apps. These elements are available in `marimo.ui`.
marimo.ui.batch
marimo.ui.button
marimo.ui.checkbox
- marimo.ui.chart
marimo.ui.code_editor
marimo.ui.dataframe
marimo.ui.data_explorer
@@ -68,3 +66,14 @@ To use a UI element, assign it to a global variable and output it in a cell.
When you interact with the frontend element, the Python object's `value`
attribute is automatically updated, and all cells referencing that object
automatically run with the element's latest value.
+
+## Integrations
+
+```{eval-rst}
+.. autosummary::
+ :nosignatures:
+
+ marimo.ui.altair_chart
+ marimo.ui.plotly
+ marimo.mpl.interactive
+```
diff --git a/docs/api/inputs/microphone.md b/docs/api/inputs/microphone.md
index dfdf53dd47..de10242595 100644
--- a/docs/api/inputs/microphone.md
+++ b/docs/api/inputs/microphone.md
@@ -1,6 +1,17 @@
# Microphone
-<iframe class="demo" src="https://components.marimo.io/?component=microphone" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ microphone = mo.ui.microphone(label="Drop a beat!")
+ return
+
+ @app.cell
+ def __():
+ mo.hstack([microphone, mo.audio(microphone.value)])
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.microphone
diff --git a/docs/api/inputs/multiselect.md b/docs/api/inputs/multiselect.md
index 0fb2b60636..594828d192 100644
--- a/docs/api/inputs/multiselect.md
+++ b/docs/api/inputs/multiselect.md
@@ -1,6 +1,18 @@
# Multiselect
-<iframe class="demo" src="https://components.marimo.io/?component=multiselect" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ options = ["Apples", "Oranges", "Pears"]
+ multiselect = mo.ui.multiselect(options=options)
+ return
+
+ @app.cell
+ def __():
+ mo.hstack([multiselect, mo.md(f"Has value: {multiselect.value}")])
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.multiselect
diff --git a/docs/api/inputs/number.md b/docs/api/inputs/number.md
index ed36b78716..9b9d8da880 100644
--- a/docs/api/inputs/number.md
+++ b/docs/api/inputs/number.md
@@ -1,6 +1,17 @@
# Number
-<iframe class="demo" src="https://components.marimo.io/?component=number" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ number = mo.ui.number(start=1, stop=20, label="Number")
+ return
+
+ @app.cell
+ def __():
+ mo.hstack([number, mo.md(f"Has value: {number.value}")])
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.number
diff --git a/docs/api/inputs/radio.md b/docs/api/inputs/radio.md
index d7fe9a76dc..638db66f6f 100644
--- a/docs/api/inputs/radio.md
+++ b/docs/api/inputs/radio.md
@@ -1,6 +1,18 @@
# Radio
-<iframe class="demo" src="https://components.marimo.io/?component=radio" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ options = ["Apples", "Oranges", "Pears"]
+ radio = mo.ui.radio(options=options)
+ return
+
+ @app.cell
+ def __():
+ mo.hstack([radio, mo.md(f"Has value: {radio.value}")])
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.radio
diff --git a/docs/api/inputs/refresh.md b/docs/api/inputs/refresh.md
index e42f9e6e15..f5408ecaf6 100644
--- a/docs/api/inputs/refresh.md
+++ b/docs/api/inputs/refresh.md
@@ -1,8 +1,20 @@
# Refresh
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ refresh = mo.ui.refresh(
+ label="Refresh",
+ options=["1s", "5s", "10s", "30s"]
+ )
+ return
-
-<iframe class="demo" src="https://components.marimo.io/?component=refresh" frameborder="no"></iframe>
+ @app.cell
+ def __():
+ mo.hstack([refresh, refresh.value])
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.refresh
diff --git a/docs/api/inputs/slider.md b/docs/api/inputs/slider.md
index dddd2f3a8c..55c6d29346 100644
--- a/docs/api/inputs/slider.md
+++ b/docs/api/inputs/slider.md
@@ -1,6 +1,17 @@
# Slider
-<iframe class="demo" src="https://components.marimo.io/?component=slider" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ slider = mo.ui.slider(start=1, stop=20, label="Slider", value=3)
+ return
+
+ @app.cell
+ def __():
+ mo.hstack([slider, mo.md(f"Has value: {slider.value}")])
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.slider
diff --git a/docs/api/inputs/switch.md b/docs/api/inputs/switch.md
index 07e6d51c38..2177b5eb53 100644
--- a/docs/api/inputs/switch.md
+++ b/docs/api/inputs/switch.md
@@ -1,6 +1,17 @@
# Switch
-<iframe class="demo" src="https://components.marimo.io/?component=switch" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ switch = mo.ui.switch(label="do not disturb")
+ return
+
+ @app.cell
+ def __():
+ mo.hstack([switch, mo.md(f"Has value: {switch.value}")])
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.switch
diff --git a/docs/api/inputs/table.md b/docs/api/inputs/table.md
index f160bf733c..13d3307ef5 100644
--- a/docs/api/inputs/table.md
+++ b/docs/api/inputs/table.md
@@ -1,6 +1,45 @@
# Table
-<iframe class="demo medium" src="https://components.marimo.io/?component=table" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ :size: large
+
+ @app.cell
+ def __():
+ table = mo.ui.table(data=office_characters, pagination=True)
+ return
+
+ @app.cell
+ def __():
+ mo.vstack([table, table.value])
+ return
+
+ @app.cell
+ def __():
+ office_characters = [
+ {"first_name": "Michael", "last_name": "Scott"},
+ {"first_name": "Jim", "last_name": "Halpert"},
+ {"first_name": "Pam", "last_name": "Beesly"},
+ {"first_name": "Dwight", "last_name": "Schrute"},
+ {"first_name": "Angela", "last_name": "Martin"},
+ {"first_name": "Kevin", "last_name": "Malone"},
+ {"first_name": "Oscar", "last_name": "Martinez"},
+ {"first_name": "Stanley", "last_name": "Hudson"},
+ {"first_name": "Phyllis", "last_name": "Vance"},
+ {"first_name": "Meredith", "last_name": "Palmer"},
+ {"first_name": "Creed", "last_name": "Bratton"},
+ {"first_name": "Ryan", "last_name": "Howard"},
+ {"first_name": "Kelly", "last_name": "Kapoor"},
+ {"first_name": "Toby", "last_name": "Flenderson"},
+ {"first_name": "Darryl", "last_name": "Philbin"},
+ {"first_name": "Erin", "last_name": "Hannon"},
+ {"first_name": "Andy", "last_name": "Bernard"},
+ {"first_name": "Jan", "last_name": "Levinson"},
+ {"first_name": "David", "last_name": "Wallace"},
+ {"first_name": "Holly", "last_name": "Flax"},
+ ]
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.table
diff --git a/docs/api/inputs/tabs.md b/docs/api/inputs/tabs.md
index eb91bac69a..c831044696 100644
--- a/docs/api/inputs/tabs.md
+++ b/docs/api/inputs/tabs.md
@@ -1,6 +1,36 @@
# Tabs
-<iframe class="demo large" src="https://components.marimo.io/?component=tabs" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ :size: large
+
+ @app.cell
+ def __():
+ import matplotlib.pyplot as plt
+ import numpy as np
+
+ # Generate some random data
+ categories = ["A", "B", "C", "D", "E"]
+ values = np.random.rand(5)
+
+ bar = plt.bar(categories, values)
+ plt.title("Random Bar Chart")
+ plt.xlabel("Categories")
+ plt.ylabel("Values")
+ None
+ return
+
+ @app.cell
+ def __():
+ mo.tabs(
+ {
+ "📈 Sales": bar,
+ "📊 Subscriptions": bar,
+ "💻 Settings": mo.ui.text(placeholder="Key"),
+ }
+ )
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.tabs
diff --git a/docs/api/inputs/text.md b/docs/api/inputs/text.md
index 262cf638f6..b1c80ce572 100644
--- a/docs/api/inputs/text.md
+++ b/docs/api/inputs/text.md
@@ -1,6 +1,17 @@
# Text
-<iframe class="demo" src="https://components.marimo.io/?component=text" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ text = mo.ui.text(placeholder="Search...", label="Filter")
+ return
+
+ @app.cell
+ def __():
+ mo.hstack([text, mo.md(f"Has value: {text.value}")])
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.text
diff --git a/docs/api/inputs/text_area.md b/docs/api/inputs/text_area.md
index e7bb51c59a..0e942d31d1 100644
--- a/docs/api/inputs/text_area.md
+++ b/docs/api/inputs/text_area.md
@@ -1,6 +1,17 @@
# Text Area
-<iframe class="demo" src="https://components.marimo.io/?component=text_area" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ text_area = mo.ui.text_area(placeholder="Search...", label="Description")
+ return
+
+ @app.cell
+ def __():
+ mo.hstack([text_area, mo.md(f"Has value: {text_area.value}")])
+ return
+```
```{eval-rst}
.. autoclass:: marimo.ui.text_area
diff --git a/docs/api/layouts/accordion.md b/docs/api/layouts/accordion.md
index 585a5ebdd6..b41626f3f9 100644
--- a/docs/api/layouts/accordion.md
+++ b/docs/api/layouts/accordion.md
@@ -1,6 +1,22 @@
# Accordion
-<iframe class="demo large" src="https://components.marimo.io/?component=accordion" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ :size: medium
+
+ @app.cell
+ def __():
+ mo.accordion(
+ {
+ "Door 1": mo.md("Nothing!"),
+ "Door 2": mo.md("Nothing!"),
+ "Door 3": mo.md(
+ "![goat](https://images.unsplash.com/photo-1524024973431-2ad916746881)"
+ ),
+ }
+ )
+ return
+```
```{eval-rst}
.. autofunction:: marimo.accordion
diff --git a/docs/api/layouts/callout.md b/docs/api/layouts/callout.md
index 72c60a3b8b..76549f3ca8 100644
--- a/docs/api/layouts/callout.md
+++ b/docs/api/layouts/callout.md
@@ -1,6 +1,26 @@
# Callout
-<iframe class="demo large" src="https://components.marimo.io/?component=callout" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ callout_kind = mo.ui.dropdown(
+ label="Color",
+ options=["neutral", "danger", "warn", "success"],
+ value="neutral",
+ )
+ return
+
+ @app.cell
+ def __():
+ callout = mo.callout("This is a callout", kind=callout_kind.value)
+ return
+
+ @app.cell
+ def __():
+ mo.vstack([callout_kind, callout], align="stretch", gap=0)
+ return
+```
```{eval-rst}
.. autofunction:: marimo.callout
diff --git a/docs/api/layouts/index.md b/docs/api/layouts/index.md
index 9799a6338a..31bec7d4c4 100644
--- a/docs/api/layouts/index.md
+++ b/docs/api/layouts/index.md
@@ -7,7 +7,6 @@
accordion
callout
- image
justify
stacks
tree
diff --git a/docs/api/layouts/stacks.md b/docs/api/layouts/stacks.md
index 4855b14159..1935225d1f 100644
--- a/docs/api/layouts/stacks.md
+++ b/docs/api/layouts/stacks.md
@@ -1,6 +1,63 @@
# Stacks
-<iframe class="demo large" src="https://components.marimo.io/?component=stacks" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ :size: large
+
+ @app.cell
+ def __():
+ def create_box(num=1):
+ box_size = 30 + num * 10
+ return mo.Html(
+ f"<div style='min-width: {box_size}px; min-height: {box_size}px; background-color: orange; text-align: center; line-height: {box_size}px'>{str(num)}</div>"
+ )
+
+
+ boxes = [create_box(i) for i in range(1, 5)]
+ return
+
+ @app.cell
+ def __():
+ justify = mo.ui.dropdown(
+ ["start", "center", "end", "space-between", "space-around"],
+ value="space-between",
+ label="justify",
+ )
+ align = mo.ui.dropdown(
+ ["start", "center", "end", "stretch"], value="center", label="align"
+ )
+ gap = mo.ui.number(start=0, step=0.25, stop=2, value=0.25, label="gap")
+ wrap = mo.ui.checkbox(label="wrap")
+ return
+
+ @app.cell
+ def __():
+ horizontal = mo.hstack(
+ boxes,
+ align=align.value,
+ justify=justify.value,
+ gap=gap.value,
+ wrap=wrap.value,
+ )
+ vertical = mo.vstack(
+ boxes,
+ align=align.value,
+ gap=gap.value,
+ )
+
+ mo.vstack(
+ [
+ mo.hstack([justify, align, gap], justify="center"),
+ horizontal,
+ mo.md("-----------------------------"),
+ vertical,
+ ],
+ align="stretch",
+ gap=1,
+ )
+ return
+
+```
```{eval-rst}
.. autofunction:: marimo.hstack
diff --git a/docs/api/layouts/tree.md b/docs/api/layouts/tree.md
index 208ad498af..df5ca6cc4f 100644
--- a/docs/api/layouts/tree.md
+++ b/docs/api/layouts/tree.md
@@ -1,6 +1,15 @@
# Tree
-<iframe class="demo large" src="https://components.marimo.io/?component=tree" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ mo.tree(
+ ["entry", "another entry", {"key": [0, mo.ui.slider(1, 10, value=5), 2]}],
+ label="A tree of elements.",
+ )
+ return
+```
```{eval-rst}
.. autofunction:: marimo.tree
diff --git a/docs/api/media/audio.md b/docs/api/media/audio.md
index 3c69ed832f..7e906816a9 100644
--- a/docs/api/media/audio.md
+++ b/docs/api/media/audio.md
@@ -1,6 +1,13 @@
# Audio
-<iframe class="demo" src="https://components.marimo.io/?component=audio" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ _src = "https://upload.wikimedia.org/wikipedia/commons/8/8c/Ivan_Ili%C4%87-Chopin_-_Prelude_no._1_in_C_major.ogg"
+ mo.audio(_src)
+ return
+```
```{eval-rst}
.. autofunction:: marimo.audio
diff --git a/docs/api/media/download.md b/docs/api/media/download.md
index 57ff5ea96c..53125d5fe8 100644
--- a/docs/api/media/download.md
+++ b/docs/api/media/download.md
@@ -1,8 +1,17 @@
# Download Media
-<!-- TODO: add interactive marimo.download doc.
-At the moment, our components app uses released versions of marimo, so these changes will lag behind. -->
-<!-- <iframe class="demo" src="https://components.marimo.io/?component=download" frameborder="no"></iframe> -->
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ download_txt = mo.download(
+ data="Hello, world!".encode("utf-8"),
+ filename="hello.txt",
+ mimetype="text/plain",
+ )
+ download_txt
+ return
+```
```{eval-rst}
.. autofunction:: marimo.download
diff --git a/docs/api/media/image.md b/docs/api/media/image.md
index 7b5ee17c84..7b0b992eb3 100644
--- a/docs/api/media/image.md
+++ b/docs/api/media/image.md
@@ -1,6 +1,15 @@
# Image
-<iframe class="demo medium" src="https://components.marimo.io/?component=image" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ @app.cell
+ def __():
+ _src = (
+ "https://images.pexels.com/photos/86596/owl-bird-eyes-eagle-owl-86596.jpeg"
+ )
+ mo.image(src=_src, width="180px", height="180px", rounded=True)
+ return
+```
```{eval-rst}
.. autofunction:: marimo.image
diff --git a/docs/api/media/video.md b/docs/api/media/video.md
index 78e78a2709..24094f57f4 100644
--- a/docs/api/media/video.md
+++ b/docs/api/media/video.md
@@ -1,6 +1,17 @@
# Video
-<!-- <iframe class="demo medium" src="https://components.marimo.io/?component=video" frameborder="no"></iframe> -->
+```{eval-rst}
+.. marimo-embed::
+ :size: medium
+
+ @app.cell
+ def __():
+ mo.video(
+ src="https://v3.cdnpk.net/videvo_files/video/free/2013-08/large_watermarked/hd0992_preview.mp4",
+ controls=False,
+ )
+ return
+```
```{eval-rst}
.. autofunction:: marimo.video
diff --git a/docs/api/plotting.md b/docs/api/plotting.md
index 8eda1f970c..530941470d 100644
--- a/docs/api/plotting.md
+++ b/docs/api/plotting.md
@@ -8,7 +8,35 @@ For more information about plotting, see the [plotting guide](../guides/plotting
## Reactive charts with Altair
-<iframe class="demo large" src="https://components.marimo.io/?component=altair-chart" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ :size: large
+
+ @app.cell
+ def __():
+ import pandas as pd
+ import pyodide
+ import micropip
+ await micropip.install('altair')
+ return
+
+ @app.cell
+ def __():
+ import altair as alt
+ cars = pyodide.http.open_url('https://vega.github.io/vega-datasets/data/cars.json')
+
+ chart = alt.Chart(cars).mark_point().encode(
+ x='Horsepower',
+ y='Miles_per_Gallon',
+ color='Origin'
+ )
+ return
+
+ @app.cell
+ def __():
+ mo.vstack([chart, mo.ui.table(chart.value)])
+ return
+```
```{eval-rst}
.. autofunction:: marimo.ui.altair_chart
diff --git a/docs/api/status.md b/docs/api/status.md
index a85c39d76e..12cc2d30ad 100644
--- a/docs/api/status.md
+++ b/docs/api/status.md
@@ -9,7 +9,30 @@ databases, or APIs.
You can display a progress bar while iterating over a collection, similar
to `tqdm`.
-<iframe class="demo medium" src="https://components.marimo.io/?component=progress-bar" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ :size: medium
+
+ @app.cell
+ def __():
+ rerun = mo.ui.button("Rerun")
+ rerun
+ return
+
+ @app.cell
+ async def __():
+ import asyncio
+ rerun
+ for _ in mo.status.progress_bar(
+ range(10),
+ title="Loading",
+ subtitle="Please wait",
+ show_eta=True,
+ show_rate=True
+ ):
+ await asyncio.sleep(0.5)
+ return
+```
```{eval-rst}
.. autofunction:: marimo.status.progress_bar
@@ -17,9 +40,28 @@ to `tqdm`.
## Spinner
-<iframe class="demo medium" src="https://components.marimo.io/?component=spinner" frameborder="no"></iframe>
+```{eval-rst}
+.. marimo-embed::
+ :size: medium
+
+ @app.cell
+ def __():
+ rerun = mo.ui.button("Rerun")
+ rerun
+ return
+
+ @app.cell
+ async def __():
+ import asyncio
+ rerun
+ with mo.status.spinner(title="Loading...") as _spinner:
+ await asyncio.sleep(1)
+ _spinner.update("Almost done")
+ await asyncio.sleep(1)
+ _spinner.update("Done")
+ return
+```
```{eval-rst}
.. autofunction:: marimo.status.spinner
```
-
diff --git a/docs/conf.py b/docs/conf.py
index 6da58084fa..da44185ee9 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -22,6 +22,7 @@ sys.path.insert(0, os.path.abspath("."))
from helpers.md2rst import md2rst
from helpers.sections import PublicMethods
+from helpers.marimo_embed import MarimoEmbed
from helpers.copy_readme import ReadmePartDirective
import marimo
@@ -130,3 +131,4 @@ def setup(app):
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#docstring-preprocessing
app.connect("autodoc-process-docstring", md2rst)
app.add_directive("readmepart", ReadmePartDirective)
+ app.add_directive("marimo-embed", MarimoEmbed)
diff --git a/docs/guides/deploying/index.md b/docs/guides/deploying/index.md
index 07988d4cea..dd877ab263 100644
--- a/docs/guides/deploying/index.md
+++ b/docs/guides/deploying/index.md
@@ -6,7 +6,7 @@
:hidden:
deploying_docker
- deploying_marimo_cloud
+ deploying_public_gallery
```
These guides help you deploy marimo notebooks.
diff --git a/docs/guides/plotting.md b/docs/guides/plotting.md
index 4cbbd3412a..561cd6a027 100644
--- a/docs/guides/plotting.md
+++ b/docs/guides/plotting.md
@@ -18,7 +18,35 @@ available in Python as a Pandas dataframe_!
## Reactive plots! ⚡
-<!-- <iframe class="demo" src="https://components.marimo.io/?component=slider" frameborder="no"></iframe> -->
+```{eval-rst}
+.. marimo-embed::
+ :size: large
+
+ @app.cell
+ def __():
+ import pandas as pd
+ import pyodide
+ import micropip
+ await micropip.install('altair')
+ return
+
+ @app.cell
+ def __():
+ import altair as alt
+ cars = pyodide.http.open_url('https://vega.github.io/vega-datasets/data/cars.json')
+
+ chart = alt.Chart(cars).mark_point().encode(
+ x='Horsepower',
+ y='Miles_per_Gallon',
+ color='Origin'
+ )
+ return
+
+ @app.cell
+ def __():
+ mo.vstack([chart, mo.ui.table(chart.value)])
+ return
+```
Use [`mo.ui.altair_chart`](../api/plotting.md#marimo.ui.altair_chart) to easily
create interactive, selectable plots: _selections you make on the frontend are
diff --git a/docs/helpers/marimo_embed.py b/docs/helpers/marimo_embed.py
new file mode 100644
index 0000000000..2ecd863a3d
--- /dev/null
+++ b/docs/helpers/marimo_embed.py
@@ -0,0 +1,58 @@
+from docutils.parsers.rst import Directive
+from docutils import nodes
+import urllib.parse
+
+
+def uri_encode_component(code: str) -> str:
+ return urllib.parse.quote(code, safe="~()*!.'")
+
+
+class MarimoEmbed(Directive):
+ required_arguments = 0
+ optional_arguments = 0
+ final_argument_whitespace = True
+ has_content = True
+ option_spec = {
+ # default, medium, large
+ "size": str,
+ # read, edit
+ "mode": str,
+ # normal, full
+ "app_width": str,
+ }
+
+ def run(self):
+ # Configs
+ size = self.options.get("size", "default")
+ mode = self.options.get("mode", "read")
+ app_width = self.options.get("app_width", "normal")
+
+ header = "\n".join(
+ [
+ "import marimo",
+ f'app = marimo.App(width="{app_width}")',
+ "",
+ ]
+ )
+ footer = "\n".join(
+ [
+ "",
+ "@app.cell",
+ "def __():",
+ " import marimo as mo",
+ " return",
+ ]
+ )
+ body = header + "\n".join(self.content) + footer
+ encoded_code = uri_encode_component(body)
+
+ # Create an iframe of the app
+ html = f"""
+ <iframe
+ class="demo {size}"
+ src="https://marimo.app/?code={encoded_code}&embed=true&mode={mode}"
+ width="100%"
+ frameBorder="0"
+ ></iframe>
+ """
+ return [nodes.raw("", html, format="html")]
diff --git a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx
index 649882208c..f6984a316a 100644
--- a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx
+++ b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx
@@ -64,7 +64,7 @@ const VerticalLayoutRenderer: React.FC<VerticalLayoutProps> = ({
{canShowCode && (
<div
className={cn(
- "right-0 top-0 z-10 m-4",
+ "right-0 top-0 z-50 m-4",
// If the notebook is static, we have a banner at the top, so
// we can't use fixed positioning. Ideally this is sticky, but the
// current dom structure makes that difficult.
@@ -74,6 +74,7 @@ const VerticalLayoutRenderer: React.FC<VerticalLayoutProps> = ({
<Button
variant="secondary"
onClick={() => setShowCode((prev) => !prev)}
+ size="sm"
data-testid="show-code"
>
<Code2Icon className="w-4 h-4 mr-2" />
diff --git a/frontend/src/components/ui/button.tsx b/frontend/src/components/ui/button.tsx
index 7b556571af..b53762786a 100644
--- a/frontend/src/components/ui/button.tsx
+++ b/frontend/src/components/ui/button.tsx
@@ -52,7 +52,7 @@ const buttonVariants = cva(
activeCommon,
),
secondary: cn(
- "bg-secondary text-secondary-foreground hover:bg-secondary/60",
+ "bg-secondary text-secondary-foreground hover:bg-secondary/80",
"border border-input shadow-smSolid",
activeCommon,
),