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.

examples: ui element usage examples (#3254)

Akshay Agrawal9de0070c9e54
diff --git a/examples/README.md b/examples/README.md
index 27c70d3d58..cb1eb40d85 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -1,10 +1,14 @@
# Examples
-This folder contains example marimo notebooks.
+This folder contains example marimo notebooks, meant to teach you how to
+use marimo's features as well as inspire you to make awesome notebooks.
-- 🖱️ [`ui/`](ui/): marimo's many UI elements or widgets
-- 🛢️ [`sql/`](sql/): using marimo's SQL cells
-- 📽️ [`layouts/`](layouts/): present notebooks as slides, add sidebars, and more
+
+- 🖱️ [`ui/`](ui/): how to use UI elements or widgets
+- 🛢️ [`sql/`](sql/): how to use SQL in marimo
+- 🛢️ [`control_flow/`](control_flow/): how to control cell execution and output display
+- 🛢️ [`markdown/`](markdown/): how to write markdown, including dynamic markdown
+- 📽️ [`layouts/`](layouts/): how to present notebooks as slides, add sidebars, and more
- 🤖 [`ai/`](ai/): AI-related examples
- 📦 [`third_party/`](third_party/): using popular third-party packages in marimo
- ☁️ [`cloud/`](cloud/): using various cloud providers
@@ -12,14 +16,17 @@ This folder contains example marimo notebooks.
- ✨ [`misc/`](misc/): miscellaneous topical examples
> [!TIP]
-> New to marimo? Run `marimo tutorial ui` at the command line first!
+> New to marimo? Run `marimo tutorial intro` at the command line first!
+
+> [!TIP]
+> Check out our [public gallery](https://marimo.io/gallery) of interactive
+> notebooks to get inspired.
> [!NOTE]
> Submit a
> [pull request](https://github.com/marimo-team/marimo/pulls) to add an example!
> We especially welcome library developers to add examples to `third_party/`.
-
## Running examples
The requirements of each notebook are serialized in them as a top-level
diff --git a/examples/control_flow/README.md b/examples/control_flow/README.md
new file mode 100644
index 0000000000..57d3cf205d
--- /dev/null
+++ b/examples/control_flow/README.md
@@ -0,0 +1,26 @@
+# Control Flow
+
+These basic examples show how to control execution of cells.
+
+> [!TIP]
+> New to marimo? Run `marimo tutorial intro` and `marimo tutorial dataflow`
+> at the command line first!
+
+_Looking for examples on making chatbots? Check out the [`ai/chat`](../ai/chat)
+examples folder_.
+
+## Running examples
+
+The requirements of each notebook are serialized in them as a top-level
+comment. Here are the steps to open an example notebook:
+
+1. [Install marimo](https://docs.marimo.io/getting_started/index.html#installation)
+2. [Install `uv`](https://github.com/astral-sh/uv/?tab=readme-ov-file#installation)
+3. Open an example with `marimo edit --sandbox <notebook.py>`.
+
+> [!TIP]
+> The [`--sandbox` flag](https://docs.marimo.io/guides/editor_features/package_management.html) opens the notebook in an isolated virtual environment,
+> automatically installing the notebook's dependencies 📦
+
+You can also open notebooks without `uv`, with just `marimo edit <notebook.py>`;
+however, you'll need to install the requirements yourself.
diff --git a/examples/control_flow/stop_execution.py b/examples/control_flow/stop_execution.py
new file mode 100644
index 0000000000..8bf66aafe4
--- /dev/null
+++ b/examples/control_flow/stop_execution.py
@@ -0,0 +1,29 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App()
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ button = mo.ui.run_button()
+ button
+ return (button,)
+
+
+def _(button, mo):
+ mo.stop(not button.value, "Click the button to continue")
+
+ mo.md("# :tada:")
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/markdown/README.md b/examples/markdown/README.md
new file mode 100644
index 0000000000..a1e3ebe732
--- /dev/null
+++ b/examples/markdown/README.md
@@ -0,0 +1,23 @@
+# Markdown
+
+These basic examples show how to use write markdown in marimo.
+
+> [!TIP]
+> New to marimo? Run `marimo tutorial intro` and `marimo tutorial markdown`
+> at the command line first!
+
+## Running examples
+
+The requirements of each notebook are serialized in them as a top-level
+comment. Here are the steps to open an example notebook:
+
+1. [Install marimo](https://docs.marimo.io/getting_started/index.html#installation)
+2. [Install `uv`](https://github.com/astral-sh/uv/?tab=readme-ov-file#installation)
+3. Open an example with `marimo edit --sandbox <notebook.py>`.
+
+> [!TIP]
+> The [`--sandbox` flag](https://docs.marimo.io/guides/editor_features/package_management.html) opens the notebook in an isolated virtual environment,
+> automatically installing the notebook's dependencies 📦
+
+You can also open notebooks without `uv`, with just `marimo edit <notebook.py>`;
+however, you'll need to install the requirements yourself.
diff --git a/examples/ui/mermaid.py b/examples/markdown/mermaid.py
similarity index 100%
rename from examples/ui/mermaid.py
rename to examples/markdown/mermaid.py
diff --git a/examples/ui/inputs.py b/examples/misc/create_your_own_shape.py
similarity index 100%
rename from examples/ui/inputs.py
rename to examples/misc/create_your_own_shape.py
diff --git a/examples/misc/explore_your_own_data.py b/examples/misc/explore_your_own_data.py
new file mode 100644
index 0000000000..92e44817de
--- /dev/null
+++ b/examples/misc/explore_your_own_data.py
@@ -0,0 +1,123 @@
+# /// script
+# requires-python = ">=3.11"
+# dependencies = [
+# "marimo",
+# "pandas==2.2.3",
+# "matplotlib==3.9.2",
+# "altair==5.4.1",
+# ]
+# ///
+
+import marimo
+
+__generated_with = "0.8.19"
+app = marimo.App(width="full")
+
+
[email protected](hide_code=True)
+def __(mo):
+ mo.md("""# Data Explorer""")
+ return
+
+
[email protected](hide_code=True)
+def __(mo):
+ sample = "https://github.com/vega/vega/blob/main/docs/data/stocks.csv"
+
+ mo.md(
+ f"""
+ This notebook lets you upload a CSV and plot its columns.
+
+ You can download a <a href="{sample}" target="_blank">sample CSV</a> if you'd like.
+ """
+ )
+ return (sample,)
+
+
[email protected](hide_code=True)
+def __(mo, uploaded_file):
+ mo.md(
+ f"""
+ {mo.hstack([mo.md("**Upload a CSV.**")], justify="center")}
+
+ {uploaded_file}
+ """
+ )
+ return
+
+
+def __(io, mo, pd, uploaded_file):
+ mo.stop(not uploaded_file.name())
+ df = pd.read_csv(io.StringIO(uploaded_file.contents().decode()))
+ return (df,)
+
+
+def __(df, mo):
+ mo.ui.table(df, page_size=5, selection=None)
+ return
+
+
+def __(df, mo):
+ plot_type = mo.ui.dropdown(
+ ["line", "hist"], value="line", label="Choose a plot type: "
+ )
+
+ x_column = mo.ui.dropdown(df.columns, label="Choose x-axis: ")
+ y_column = mo.ui.dropdown(df.columns, label="Choose y-axis: ")
+ color_column = mo.ui.dropdown(df.columns, label="Choose color-axis: ")
+ return color_column, plot_type, x_column, y_column
+
+
+def __(color_column, mo, plot_type, x_column, y_column):
+ mo.hstack(
+ [x_column, y_column, color_column, plot_type], justify="space-around"
+ ).callout(kind="warn" if not x_column.value else "neutral")
+ return
+
+
+def __(alt, color_column, df, mo, plot_type, x_column, y_column):
+ mo.stop(not x_column.value)
+
+
+ def plot(x_column, y_column, color_column):
+ y_column = y_column or "count()"
+ title = f"{y_column} by {x_column}"
+ encoding = {"x": x_column, "y": y_column}
+ if color_column:
+ encoding["color"] = color_column
+ if plot_type.value == "line":
+ chart = alt.Chart(df).mark_line()
+ else:
+ chart = alt.Chart(df).mark_bar().encode(x=alt.X(x_column, bin=True))
+ return chart.encode(**encoding).properties(title=title, width="container")
+
+
+ plot(x_column.value, y_column.value, color_column.value)
+ return (plot,)
+
+
+def __(mo):
+ uploaded_file = mo.ui.file(filetypes=[".csv"], kind="area")
+ return (uploaded_file,)
+
+
+def __():
+ import marimo as mo
+ import altair as alt
+
+
+ import io
+ import matplotlib.pyplot as plt
+ import pandas as pd
+ return alt, io, mo, pd, plt
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/filterable_table.py b/examples/misc/filterable_table.py
similarity index 100%
rename from examples/ui/filterable_table.py
rename to examples/misc/filterable_table.py
diff --git a/examples/misc/iss.py b/examples/misc/iss.py
new file mode 100644
index 0000000000..1f4fba9959
--- /dev/null
+++ b/examples/misc/iss.py
@@ -0,0 +1,169 @@
+# /// script
+# requires-python = ">=3.11"
+# dependencies = [
+# "pandas==2.2.3",
+# "vega-datasets==0.9.0",
+# "requests==2.32.3",
+# "altair==5.4.1",
+# "marimo",
+# ]
+# ///
+
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="full")
+
+
+def _(
+ chart,
+ iss_df,
+ mo,
+ n_points_slider,
+ refresh_interval_slider,
+ refresher,
+):
+ mo.hstack(
+ [
+ mo.vstack(
+ [
+ mo.md(
+ "## Settings | [`marimo.ui.slider`](https://docs.marimo.io/api/inputs/slider.html), [`marimo.ui.refresh`](https://docs.marimo.io/recipes.html#run-a-cell-on-a-timer)\n---"
+ ),
+ refresh_interval_slider,
+ n_points_slider,
+ refresher,
+ mo.md(
+ "## ISS Positions | [`marimo.ui.altair_chart`](https://docs.marimo.io/api/plotting.html#marimo.ui.altair_chart)\n---"
+ ),
+ mo.as_html(chart).style({"width": "700px"}),
+ ],
+ align="center",
+ ),
+ mo.vstack(
+ [
+ mo.md(
+ "## Data | [`marimo.as_html`](https://docs.marimo.io/api/html.html)`(pd.DataFrame)`\n---"
+ ),
+ mo.as_html(iss_df),
+ ]
+ ),
+ ],
+ justify="center",
+ wrap=True,
+ gap=3,
+ )
+ return
+
+
+def _(alt, get_iss_positions, sphere, world):
+ hover = alt.selection_point(on="mouseover", clear="mouseout")
+
+ # iss positions
+ iss_df = get_iss_positions()
+ iss = (
+ alt.Chart(iss_df[["longitude", "latitude", "timestamp"]])
+ .mark_circle(
+ stroke="black",
+ size=100,
+ )
+ .encode(
+ longitude=alt.Longitude("longitude:Q"),
+ latitude="latitude:Q",
+ fill=alt.Fill(
+ "timestamp:Q", scale=alt.Scale(scheme="purples"), legend=None
+ ),
+ strokeWidth=alt.condition(
+ hover, alt.value(3, empty=False), alt.value(0)
+ ),
+ tooltip=[
+ alt.Tooltip("longitude:Q", title="Longitude", format=".4f"),
+ alt.Tooltip("latitude:Q", title="Latitude", format=".4f"),
+ alt.Tooltip(
+ "timestamp:T", title="Timestamp", format="%Y-%m-%d %H:%M:%S"
+ ),
+ ],
+ )
+ .add_params(hover)
+ )
+
+ chart = (
+ alt.layer(sphere, world, iss)
+ .project(type="naturalEarth1")
+ .properties(width=640, title="")
+ )
+ return chart, hover, iss, iss_df
+
+
+def _(alt, data):
+ # load geo data from Vega Datasets
+ countries = alt.topo_feature(data.world_110m.url, 'countries')
+
+ # world base
+ sphere = alt.Chart(alt.sphere()).mark_geoshape(
+ fill="aliceblue", stroke="black", strokeWidth=1.5
+ )
+
+ # world map
+ world = alt.Chart(countries).mark_geoshape(
+ fill="mintcream", stroke="black", strokeWidth=0.35
+ )
+ return countries, sphere, world
+
+
+def _(
+ n_points_slider,
+ pd,
+ refresh_interval_slider,
+ refresher,
+ requests,
+ time,
+):
+ def get_iss_positions(refresher=refresher):
+ refresher
+ timepoints = [int(time())]
+ while len(timepoints) <= n_points_slider.value:
+ timepoints.append(timepoints[-1] - refresh_interval_slider.value)
+ else:
+ timepoints.pop(0)
+ timepoints_str = str(timepoints)[1:-1].replace(" ", "")
+ iss_url = f"https://api.wheretheiss.at/v1/satellites/25544/positions?timestamps={timepoints_str}"
+ response = requests.get(iss_url)
+ df = pd.DataFrame(response.json())
+ df['timestamp'] = pd.to_datetime(df.timestamp, unit='s')
+ return df[['timestamp','latitude','longitude','altitude','velocity','visibility']]
+ return (get_iss_positions,)
+
+
+def _(mo, refresh_interval_slider):
+ refresher = mo.ui.refresh(default_interval=f"{refresh_interval_slider.value}s")
+ return (refresher,)
+
+
+def _(mo):
+ refresh_interval_slider = mo.ui.slider(start=5, stop=60, step=1, value=10, label="refresh interval (default = 10 sec)")
+ n_points_slider = mo.ui.slider(start=5, stop=30, step=1, value=15, label="number of points (default = 15)")
+ return n_points_slider, refresh_interval_slider
+
+
+def _():
+ import altair as alt
+ import marimo as mo
+ import pandas as pd
+ import requests
+ from time import time
+ from vega_datasets import data
+
+ pd.options.display.max_rows = 30
+ return alt, data, mo, pd, requests, time
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/reactive_plots.py b/examples/misc/reactive_plots.py
similarity index 100%
rename from examples/ui/reactive_plots.py
rename to examples/misc/reactive_plots.py
diff --git a/examples/ui/task_list.py b/examples/misc/task_list.py
similarity index 100%
rename from examples/ui/task_list.py
rename to examples/misc/task_list.py
diff --git a/examples/ui/README.md b/examples/ui/README.md
index e8c2df4ef3..2e4b6079f7 100644
--- a/examples/ui/README.md
+++ b/examples/ui/README.md
@@ -1,6 +1,6 @@
# UI 🖱️
-These examples showcase how to use marimo's built-in UI elements.
+These basic examples show how to use marimo's built-in UI elements.
> [!TIP]
> New to marimo? Run `marimo tutorial intro` and `marimo tutorial ui`
diff --git a/examples/ui/array_element.py b/examples/ui/array_element.py
new file mode 100644
index 0000000000..469fadb1eb
--- /dev/null
+++ b/examples/ui/array_element.py
@@ -0,0 +1,27 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ array = mo.ui.array([mo.ui.text(), mo.ui.slider(1, 10), mo.ui.date()])
+ array
+ return (array,)
+
+
+def _(array):
+ array.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/arrays_and_dicts.py b/examples/ui/arrays_and_dicts.py
index 6389554c66..7211d78edc 100644
--- a/examples/ui/arrays_and_dicts.py
+++ b/examples/ui/arrays_and_dicts.py
@@ -7,18 +7,25 @@
import marimo
-__generated_with = "0.9.14"
+__generated_with = "0.10.6"
app = marimo.App()
+def _():
+ import marimo as mo
+ import random
+ return mo, random
+
+
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md("""# Arrays and Dictionaries""")
return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
Use `mo.ui.array` and `mo.ui.dictionary` to create UI elements that wrap
@@ -33,25 +40,25 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
create = mo.ui.button(label="Create new collections")
return (create,)
@app.cell
-def __(create):
+def _(create):
create.center()
return
@app.cell
-def __(mo):
+def _(mo):
mo.md("""UI Elements ...""")
return
@app.cell
-def __(create, mo, random):
+def _(create, mo, random):
create
array = mo.ui.array(
@@ -67,19 +74,19 @@ def __(create, mo, random):
@app.cell
-def __(mo):
+def _(mo):
mo.md("""... and their values""")
return
@app.cell
-def __(array, dictionary, mo):
+def _(array, dictionary, mo):
mo.hstack([array.value, dictionary.value], justify="space-around")
return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
Key difference between marimo dict and standard python dict:
@@ -91,7 +98,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(create, mo):
+def _(create, mo):
create
slider = mo.ui.slider(1, 10, show_value=True)
@@ -124,7 +131,7 @@ def __(create, mo):
@app.cell(hide_code=True)
-def __(mo, mo_d, py_d):
+def _(mo, mo_d, py_d):
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(
@@ -138,17 +145,10 @@ def __(mo, mo_d, py_d):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
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.""")
return
-def __():
- import marimo as mo
- import random
- return mo, random
-
-
if __name__ == "__main__":
app.run()
diff --git a/examples/ui/batch.py b/examples/ui/batch.py
new file mode 100644
index 0000000000..3bb21da747
--- /dev/null
+++ b/examples/ui/batch.py
@@ -0,0 +1,29 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ element = mo.md("{start} → {end}").batch(
+ start=mo.ui.date(label="Start"), end=mo.ui.date(label="End")
+ )
+ element
+ return (element,)
+
+
+def _(element):
+ element.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/batch_and_form.py b/examples/ui/batch_and_form.py
index 095cb61437..a74cab88fa 100644
--- a/examples/ui/batch_and_form.py
+++ b/examples/ui/batch_and_form.py
@@ -7,18 +7,24 @@
import marimo
-__generated_with = "0.8.19"
+__generated_with = "0.10.6"
app = marimo.App()
@app.cell
-def __(mo):
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
mo.md("""# Batch and Form""")
return
@app.cell
-def __(mo):
+def _(mo):
mo.md(
"""
Make custom UI elements using `batch()`, and turn any UI element
@@ -29,7 +35,7 @@ def __(mo):
@app.cell
-def __(mo, reset):
+def _(mo, reset):
reset
variables = (
@@ -54,7 +60,7 @@ def __(mo, reset):
@app.cell
-def __(mo, reset, submitted_values, variables):
+def _(mo, reset, submitted_values, variables):
if variables.value is not None:
submitted_values["x"].add(variables.value["x"])
submitted_values["y"].add(variables.value["y"])
@@ -77,7 +83,7 @@ def __(mo, reset, submitted_values, variables):
@app.cell
-def __(reset):
+def _(reset):
reset
submitted_values = {"x": set(), "y": set()}
@@ -85,16 +91,10 @@ def __(reset):
@app.cell
-def __(mo):
+def _(mo):
reset = mo.ui.button(label="reset history")
return (reset,)
-def __():
- import marimo as mo
- return (mo,)
-
-
if __name__ == "__main__":
app.run()
diff --git a/examples/ui/chat.py b/examples/ui/chat.py
new file mode 100644
index 0000000000..b27e35968b
--- /dev/null
+++ b/examples/ui/chat.py
@@ -0,0 +1,34 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ def simple_echo_model(messages, config):
+ return f"You said: {messages[-1].content}"
+
+ chatbot = mo.ui.chat(
+ simple_echo_model,
+ prompts=["Hello", "How are you?"],
+ show_configuration_controls=True
+ )
+ chatbot
+ return chatbot, simple_echo_model
+
+
+def _(chatbot):
+ chatbot.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/checkbox.py b/examples/ui/checkbox.py
new file mode 100644
index 0000000000..e8d4b6e11f
--- /dev/null
+++ b/examples/ui/checkbox.py
@@ -0,0 +1,27 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ checkbox = mo.ui.checkbox(label="check me")
+ checkbox
+ return (checkbox,)
+
+
+def _(checkbox):
+ checkbox.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/code_editor.py b/examples/ui/code_editor.py
new file mode 100644
index 0000000000..f26bfb88a9
--- /dev/null
+++ b/examples/ui/code_editor.py
@@ -0,0 +1,35 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ initial_code = """# implement foo below
+ def foo():
+ ...
+ """
+
+ editor = mo.ui.code_editor(
+ value=initial_code,
+ language="python"
+ )
+ editor
+ return editor, initial_code
+
+
+def _(editor):
+ editor.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/data_explorer.py b/examples/ui/data_explorer.py
index 92e44817de..7fca1940d0 100644
--- a/examples/ui/data_explorer.py
+++ b/examples/ui/data_explorer.py
@@ -1,123 +1,41 @@
# /// script
-# requires-python = ">=3.11"
+# requires-python = ">=3.12"
# dependencies = [
-# "marimo",
-# "pandas==2.2.3",
-# "matplotlib==3.9.2",
-# "altair==5.4.1",
+# "polars==1.17.1",
+# "vega-datasets==0.9.0",
# ]
# ///
import marimo
-__generated_with = "0.8.19"
-app = marimo.App(width="full")
-
-
[email protected](hide_code=True)
-def __(mo):
- mo.md("""# Data Explorer""")
- return
-
-
[email protected](hide_code=True)
-def __(mo):
- sample = "https://github.com/vega/vega/blob/main/docs/data/stocks.csv"
-
- mo.md(
- f"""
- This notebook lets you upload a CSV and plot its columns.
-
- You can download a <a href="{sample}" target="_blank">sample CSV</a> if you'd like.
- """
- )
- return (sample,)
-
-
[email protected](hide_code=True)
-def __(mo, uploaded_file):
- mo.md(
- f"""
- {mo.hstack([mo.md("**Upload a CSV.**")], justify="center")}
-
- {uploaded_file}
- """
- )
- return
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
@app.cell
-def __(io, mo, pd, uploaded_file):
- mo.stop(not uploaded_file.name())
- df = pd.read_csv(io.StringIO(uploaded_file.contents().decode()))
- return (df,)
+def _():
+ import marimo as mo
+ return (mo,)
@app.cell
-def __(df, mo):
- mo.ui.table(df, page_size=5, selection=None)
- return
+def _():
+ from vega_datasets import data
+ return (data,)
@app.cell
-def __(df, mo):
- plot_type = mo.ui.dropdown(
- ["line", "hist"], value="line", label="Choose a plot type: "
- )
-
- x_column = mo.ui.dropdown(df.columns, label="Choose x-axis: ")
- y_column = mo.ui.dropdown(df.columns, label="Choose y-axis: ")
- color_column = mo.ui.dropdown(df.columns, label="Choose color-axis: ")
- return color_column, plot_type, x_column, y_column
+def _(data, mo):
+ explorer = mo.ui.data_explorer(data.iris())
+ explorer
+ return (explorer,)
@app.cell
-def __(color_column, mo, plot_type, x_column, y_column):
- mo.hstack(
- [x_column, y_column, color_column, plot_type], justify="space-around"
- ).callout(kind="warn" if not x_column.value else "neutral")
+def _(explorer):
+ explorer.value
return
-def __(alt, color_column, df, mo, plot_type, x_column, y_column):
- mo.stop(not x_column.value)
-
-
- def plot(x_column, y_column, color_column):
- y_column = y_column or "count()"
- title = f"{y_column} by {x_column}"
- encoding = {"x": x_column, "y": y_column}
- if color_column:
- encoding["color"] = color_column
- if plot_type.value == "line":
- chart = alt.Chart(df).mark_line()
- else:
- chart = alt.Chart(df).mark_bar().encode(x=alt.X(x_column, bin=True))
- return chart.encode(**encoding).properties(title=title, width="container")
-
-
- plot(x_column.value, y_column.value, color_column.value)
- return (plot,)
-
-
-def __(mo):
- uploaded_file = mo.ui.file(filetypes=[".csv"], kind="area")
- return (uploaded_file,)
-
-
-def __():
- import marimo as mo
- import altair as alt
-
-
- import io
- import matplotlib.pyplot as plt
- import pandas as pd
- return alt, io, mo, pd, plt
-
-
if __name__ == "__main__":
app.run()
diff --git a/examples/ui/dataframe.py b/examples/ui/dataframe.py
new file mode 100644
index 0000000000..9e2882d753
--- /dev/null
+++ b/examples/ui/dataframe.py
@@ -0,0 +1,41 @@
+# /// script
+# requires-python = ">=3.12"
+# dependencies = [
+# "marimo",
+# "vega-datasets==0.9.0",
+# ]
+# ///
+
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _():
+ from vega_datasets import data
+ return (data,)
+
+
+def _(data, mo):
+ dataframe_transformer = mo.ui.dataframe(data.iris())
+ dataframe_transformer
+ return (dataframe_transformer,)
+
+
+def _(dataframe_transformer):
+ dataframe_transformer.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/date.py b/examples/ui/date.py
new file mode 100644
index 0000000000..c70b85b269
--- /dev/null
+++ b/examples/ui/date.py
@@ -0,0 +1,27 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ date = mo.ui.date()
+ date
+ return (date,)
+
+
+def _(date):
+ date.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/date_range.py b/examples/ui/date_range.py
new file mode 100644
index 0000000000..e845cd8ad0
--- /dev/null
+++ b/examples/ui/date_range.py
@@ -0,0 +1,31 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ import datetime as dt
+
+ date_range = mo.ui.date_range(
+ start=dt.date(2023, 1, 1), stop=dt.date(2023, 12, 31)
+ )
+ date_range
+ return date_range, dt
+
+
+def _(date_range):
+ date_range.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/datetime_input.py b/examples/ui/datetime_input.py
new file mode 100644
index 0000000000..3ffdcb5b3e
--- /dev/null
+++ b/examples/ui/datetime_input.py
@@ -0,0 +1,27 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ datetime = mo.ui.datetime(label="datetime")
+ datetime
+ return (datetime,)
+
+
+def _(datetime):
+ datetime.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/dictionary.py b/examples/ui/dictionary.py
new file mode 100644
index 0000000000..2bf58c6c44
--- /dev/null
+++ b/examples/ui/dictionary.py
@@ -0,0 +1,27 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ dictionary = mo.ui.dictionary({"name": mo.ui.text(), "age": mo.ui.slider(1, 100)})
+ dictionary
+ return (dictionary,)
+
+
+def _(dictionary):
+ dictionary.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/dropdown.py b/examples/ui/dropdown.py
new file mode 100644
index 0000000000..786c782649
--- /dev/null
+++ b/examples/ui/dropdown.py
@@ -0,0 +1,27 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ dropdown = mo.ui.dropdown(["Option A", "Option B", "Option C"])
+ dropdown
+ return (dropdown,)
+
+
+def _(dropdown):
+ dropdown.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/file.py b/examples/ui/file.py
new file mode 100644
index 0000000000..a2a8f2ba31
--- /dev/null
+++ b/examples/ui/file.py
@@ -0,0 +1,27 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ file = mo.ui.file()
+ file
+ return (file,)
+
+
+def _(file):
+ file.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/file_browser.py b/examples/ui/file_browser.py
new file mode 100644
index 0000000000..b345260946
--- /dev/null
+++ b/examples/ui/file_browser.py
@@ -0,0 +1,27 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ file_browser = mo.ui.file_browser()
+ file_browser
+ return (file_browser,)
+
+
+def _(file_browser):
+ file_browser.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/form.py b/examples/ui/form.py
new file mode 100644
index 0000000000..ca8c9165cb
--- /dev/null
+++ b/examples/ui/form.py
@@ -0,0 +1,43 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ # Create a form with multiple elements
+ form = (
+ mo.md(
+ """
+ **Your form.**
+
+ {name}
+
+ {date}
+ """
+ )
+ .batch(
+ name=mo.ui.text(label="name"),
+ date=mo.ui.date(label="date"),
+ )
+ .form(show_clear_button=True, bordered=False)
+ )
+ form
+ return (form,)
+
+
+def _(form):
+ form.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/microphone.py b/examples/ui/microphone.py
new file mode 100644
index 0000000000..98a46826e0
--- /dev/null
+++ b/examples/ui/microphone.py
@@ -0,0 +1,29 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ microphone = mo.ui.microphone(label="Drop a beat!")
+ microphone
+ return (microphone,)
+
+
+def _(microphone, mo):
+ mo.stop(not microphone.value.getvalue(), "Record something with the microphone! 👆")
+
+ mo.audio(microphone.value)
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/multiselect.py b/examples/ui/multiselect.py
new file mode 100644
index 0000000000..71a48f36a1
--- /dev/null
+++ b/examples/ui/multiselect.py
@@ -0,0 +1,27 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ multiselect = mo.ui.multiselect(options=["Apples", "Oranges", "Pears"])
+ multiselect
+ return (multiselect,)
+
+
+def _(multiselect):
+ multiselect.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/number.py b/examples/ui/number.py
new file mode 100644
index 0000000000..d7bdf57b7b
--- /dev/null
+++ b/examples/ui/number.py
@@ -0,0 +1,27 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App()
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ number = mo.ui.number(start=1, stop=10)
+ number
+ return (number,)
+
+
+def _(number):
+ number.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/radio.py b/examples/ui/radio.py
new file mode 100644
index 0000000000..a461d77d50
--- /dev/null
+++ b/examples/ui/radio.py
@@ -0,0 +1,27 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App()
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ radio = mo.ui.radio(["A", "B", "C"])
+ radio
+ return (radio,)
+
+
+def _(radio):
+ radio.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/range_slider.py b/examples/ui/range_slider.py
new file mode 100644
index 0000000000..2f7455f553
--- /dev/null
+++ b/examples/ui/range_slider.py
@@ -0,0 +1,27 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App()
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ range_slider = mo.ui.range_slider(start=1, stop=10)
+ range_slider
+ return (range_slider,)
+
+
+def _(range_slider):
+ range_slider.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/refresh.py b/examples/ui/refresh.py
index 124b8d6d7d..ca748b5674 100644
--- a/examples/ui/refresh.py
+++ b/examples/ui/refresh.py
@@ -1,135 +1,26 @@
-# /// script
-# requires-python = ">=3.11"
-# dependencies = [
-# "pandas==2.2.3",
-# "vega-datasets==0.9.0",
-# "requests==2.32.3",
-# "altair==5.4.1",
-# "marimo",
-# ]
-# ///
import marimo
-__generated_with = "0.1.68"
-app = marimo.App(width="full")
+__generated_with = "0.10.6"
+app = marimo.App()
@app.cell
-def __(
- chart,
- iss_df,
- mo,
- n_points_slider,
- refresh_interval_slider,
- refresher,
-):
- mo.hstack([
- mo.vstack([
- mo.md("## Settings | [`marimo.ui.slider`](https://docs.marimo.io/api/inputs/slider.html), [`marimo.ui.refresh`](https://docs.marimo.io/recipes.html#run-a-cell-on-a-timer)\n---"),
- refresh_interval_slider,
- n_points_slider,
- refresher,
- mo.md("## ISS Positions | [`marimo.ui.altair_chart`](https://docs.marimo.io/api/plotting.html#marimo.ui.altair_chart)\n---"),
- mo.as_html(chart).style({"width": "700px"})
- ], align="center"),
- mo.vstack([
- mo.md("## Data | [`marimo.as_html`](https://docs.marimo.io/api/html.html)`(pd.DataFrame)`\n---"),
- mo.as_html(iss_df)
- ])
- ], justify="center", wrap=True, gap=3)
- return
-
-
-def __(alt, get_iss_positions, sphere, world):
- hover=alt.selection_point(on="mouseover", clear="mouseout")
-
- # iss positions
- iss_df = get_iss_positions()
- iss = alt.Chart(iss_df[['longitude','latitude','timestamp']]).mark_circle(
- stroke='black', size=100,
- ).encode(
- longitude=alt.Longitude('longitude:Q'),
- latitude='latitude:Q',
- fill=alt.Fill('timestamp:Q', scale=alt.Scale(scheme='purples'), legend=None),
- strokeWidth=alt.condition(hover, alt.value(3, empty=False), alt.value(0)),
- tooltip=[
- alt.Tooltip('longitude:Q', title='Longitude', format='.4f'),
- alt.Tooltip('latitude:Q', title='Latitude', format='.4f'),
- alt.Tooltip('timestamp:T', title='Timestamp', format='%Y-%m-%d %H:%M:%S')
- ]
- ).add_params(hover)
-
- chart = alt.layer(sphere, world, iss).project(type="naturalEarth1").properties(width=640, title="")
- return chart, hover, iss, iss_df
-
-
-def __(alt, data):
- # load geo data from Vega Datasets
- countries = alt.topo_feature(data.world_110m.url, 'countries')
-
- # world base
- sphere = alt.Chart(alt.sphere()).mark_geoshape(
- fill="aliceblue", stroke="black", strokeWidth=1.5
- )
-
- # world map
- world = alt.Chart(countries).mark_geoshape(
- fill="mintcream", stroke="black", strokeWidth=0.35
- )
- return countries, sphere, world
-
-
-def __(
- n_points_slider,
- pd,
- refresh_interval_slider,
- refresher,
- requests,
- time,
-):
- def get_iss_positions(refresher=refresher):
- refresher
- timepoints = [int(time())]
- while len(timepoints) <= n_points_slider.value:
- timepoints.append(timepoints[-1] - refresh_interval_slider.value)
- else:
- timepoints.pop(0)
- timepoints_str = str(timepoints)[1:-1].replace(" ", "")
- iss_url = f"https://api.wheretheiss.at/v1/satellites/25544/positions?timestamps={timepoints_str}"
- response = requests.get(iss_url)
- df = pd.DataFrame(response.json())
- df['timestamp'] = pd.to_datetime(df.timestamp, unit='s')
- return df[['timestamp','latitude','longitude','altitude','velocity','visibility']]
- return get_iss_positions,
-
-
-def __(mo, refresh_interval_slider):
- refresher = mo.ui.refresh(default_interval=f"{refresh_interval_slider.value}s")
- return refresher,
+def _():
+ import marimo as mo
+ return (mo,)
@app.cell
-def __(mo):
- refresh_interval_slider = mo.ui.slider(start=5, stop=60, step=1, value=10, label="refresh interval (default = 10 sec)")
- n_points_slider = mo.ui.slider(start=5, stop=30, step=1, value=15, label="number of points (default = 15)")
- return n_points_slider, refresh_interval_slider
+def _(mo):
+ refresh = mo.ui.refresh(default_interval=1)
+ refresh
+ return (refresh,)
@app.cell
-def __():
- import altair as alt
- import marimo as mo
- import pandas as pd
- import requests
- from time import time
- from vega_datasets import data
-
- pd.options.display.max_rows = 30
- return alt, data, mo, pd, requests, time
+def _(refresh):
+ print(refresh.value)
+ return
if __name__ == "__main__":
diff --git a/examples/ui/run_button.py b/examples/ui/run_button.py
new file mode 100644
index 0000000000..ed3b901adc
--- /dev/null
+++ b/examples/ui/run_button.py
@@ -0,0 +1,33 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App()
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ first_button = mo.ui.run_button(label="Option 1")
+ second_button = mo.ui.run_button(label="Option 2")
+ first_button, second_button
+ return first_button, second_button
+
+
+def _(first_button, second_button):
+ if first_button.value:
+ print("You chose option 1!")
+ elif second_button.value:
+ print("You chose option 2!")
+ else:
+ print("Click a button!")
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/slider.py b/examples/ui/slider.py
new file mode 100644
index 0000000000..db51799f32
--- /dev/null
+++ b/examples/ui/slider.py
@@ -0,0 +1,27 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ slider = mo.ui.slider(start=1, stop=10)
+ slider
+ return (slider,)
+
+
+def _(slider):
+ slider.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/switch.py b/examples/ui/switch.py
new file mode 100644
index 0000000000..de915ec2b3
--- /dev/null
+++ b/examples/ui/switch.py
@@ -0,0 +1,27 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App()
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ switch = mo.ui.switch()
+ switch
+ return (switch,)
+
+
+def _(switch):
+ switch.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/table.py b/examples/ui/table.py
index 191b44311f..f1434a1e5b 100644
--- a/examples/ui/table.py
+++ b/examples/ui/table.py
@@ -1,228 +1,34 @@
-# /// script
-# requires-python = ">=3.11"
-# dependencies = [
-# "marimo",
-# ]
-# ///
-
import marimo
-__generated_with = "0.8.19"
+__generated_with = "0.10.6"
app = marimo.App()
[email protected](hide_code=True)
-def __(mo):
- mo.md(
- """
- # Tables
-
- > “Sometimes I’ll start a sentence and I don’t even know where it’s going. I just hope I find it along the way.”
- — Michael Scott
- """
- )
- return
-
-
[email protected](hide_code=True)
-def __(mo):
- mo.md("""_Create rich tables with selectable rows using_ `mo.ui.table`.""")
- return
-
-
-def __(mo):
- mo.md("""**Single selection.**""")
- return
-
-
-def __(mo, office_characters):
- single_select_table = mo.ui.table(
- office_characters,
- selection="single",
- pagination=True,
- )
- return (single_select_table,)
-
-
@app.cell
-def __(mo, single_select_table):
- mo.ui.tabs({"table": single_select_table, "selection": single_select_table.value})
- return
-
-
-def __(mo):
- mo.md("""**Multi-selection.**""")
- return
-
-
-def __(mo, office_characters):
- multi_select_table = mo.ui.table(
- office_characters,
- selection="multi",
- pagination=True,
- )
- return (multi_select_table,)
-
-
-def __(mo, multi_select_table):
- mo.ui.tabs({"table": multi_select_table, "selection": multi_select_table.value})
- return
-
-
-def __(mo):
- mo.md("""**No selection.**""")
- return
+def _():
+ import marimo as mo
+ return (mo,)
@app.cell
-def __(mo, office_characters):
+def _(mo):
+ # ui.table accepts a list of rows as dicts, or a dict mapping column names to values,
+ # or a dataframe-like object
table = mo.ui.table(
- office_characters,
- label="Employees",
- selection=None,
+ [
+ {"first_name": "Michael", "last_name": "Scott"},
+ {"first_name": "Jim", "last_name": "Halpert"},
+ {"first_name": "Pam", "last_name": "Beesly"},
+ ]
)
-
table
return (table,)
@app.cell
-def __(mo):
- office_characters = [
- {
- "first_name": "Michael",
- "last_name": "Scott",
- "skill": mo.ui.slider(1, 10, value=3),
- "favorite place": mo.image(src="https://picsum.photos/100", rounded=True),
- },
- {
- "first_name": "Jim",
- "last_name": "Halpert",
- "skill": mo.ui.slider(1, 10, value=7),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Pam",
- "last_name": "Beesly",
- "skill": mo.ui.slider(1, 10, value=3),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Dwight",
- "last_name": "Schrute",
- "skill": mo.ui.slider(1, 10, value=7),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Angela",
- "last_name": "Martin",
- "skill": mo.ui.slider(1, 10, value=5),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Kevin",
- "last_name": "Malone",
- "skill": mo.ui.slider(1, 10, value=3),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Oscar",
- "last_name": "Martinez",
- "skill": mo.ui.slider(1, 10, value=3),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Stanley",
- "last_name": "Hudson",
- "skill": mo.ui.slider(1, 10, value=5),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Phyllis",
- "last_name": "Vance",
- "skill": mo.ui.slider(1, 10, value=5),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Meredith",
- "last_name": "Palmer",
- "skill": mo.ui.slider(1, 10, value=7),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Creed",
- "last_name": "Bratton",
- "skill": mo.ui.slider(1, 10, value=3),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Ryan",
- "last_name": "Howard",
- "skill": mo.ui.slider(1, 10, value=5),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Kelly",
- "last_name": "Kapoor",
- "skill": mo.ui.slider(1, 10, value=3),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Toby",
- "last_name": "Flenderson",
- "skill": mo.ui.slider(1, 10, value=3),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Darryl",
- "last_name": "Philbin",
- "skill": mo.ui.slider(1, 10, value=7),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Erin",
- "last_name": "Hannon",
- "skill": mo.ui.slider(1, 10, value=5),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Andy",
- "last_name": "Bernard",
- "skill": mo.ui.slider(1, 10, value=5),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Jan",
- "last_name": "Levinson",
- "skill": mo.ui.slider(1, 10, value=5),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "David",
- "last_name": "Wallace",
- "skill": mo.ui.slider(1, 10, value=3),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- {
- "first_name": "Holly",
- "last_name": "Flax",
- "skill": mo.ui.slider(1, 10, value=7),
- "favorite place": mo.image(src="https://picsum.photos/100"),
- },
- ]
- return (office_characters,)
-
-
-def __():
- import marimo as mo
- return (mo,)
+def _(table):
+ table.value
+ return
if __name__ == "__main__":
diff --git a/examples/ui/table_advanced.py b/examples/ui/table_advanced.py
new file mode 100644
index 0000000000..8d5b79f912
--- /dev/null
+++ b/examples/ui/table_advanced.py
@@ -0,0 +1,229 @@
+# /// script
+# requires-python = ">=3.11"
+# dependencies = [
+# "marimo",
+# ]
+# ///
+
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App()
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
[email protected](hide_code=True)
+def _(mo):
+ mo.md(
+ """
+ # Tables
+
+ > “Sometimes I’ll start a sentence and I don’t even know where it’s going. I just hope I find it along the way.”
+ — Michael Scott
+ """
+ )
+ return
+
+
[email protected](hide_code=True)
+def _(mo):
+ mo.md("""_Create rich tables with selectable rows using_ `mo.ui.table`.""")
+ return
+
+
[email protected](hide_code=True)
+def _(mo):
+ mo.md("""**Single selection.**""")
+ return
+
+
+def _(mo, office_characters):
+ single_select_table = mo.ui.table(
+ office_characters,
+ selection="single",
+ pagination=True,
+ )
+ return (single_select_table,)
+
+
+def _(mo, single_select_table):
+ mo.ui.tabs({"table": single_select_table, "selection": single_select_table.value})
+ return
+
+
[email protected](hide_code=True)
+def _(mo):
+ mo.md("""**Multi-selection.**""")
+ return
+
+
+def _(mo, office_characters):
+ multi_select_table = mo.ui.table(
+ office_characters,
+ selection="multi",
+ pagination=True,
+ )
+ return (multi_select_table,)
+
+
+def _(mo, multi_select_table):
+ mo.ui.tabs({"table": multi_select_table, "selection": multi_select_table.value})
+ return
+
+
[email protected](hide_code=True)
+def _(mo):
+ mo.md("""**No selection.**""")
+ return
+
+
+def _(mo, office_characters):
+ table = mo.ui.table(
+ office_characters,
+ label="Employees",
+ selection=None,
+ )
+
+ table
+ return (table,)
+
+
+def _(mo):
+ office_characters = [
+ {
+ "first_name": "Michael",
+ "last_name": "Scott",
+ "skill": mo.ui.slider(1, 10, value=3),
+ "favorite place": mo.image(src="https://picsum.photos/100", rounded=True),
+ },
+ {
+ "first_name": "Jim",
+ "last_name": "Halpert",
+ "skill": mo.ui.slider(1, 10, value=7),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Pam",
+ "last_name": "Beesly",
+ "skill": mo.ui.slider(1, 10, value=3),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Dwight",
+ "last_name": "Schrute",
+ "skill": mo.ui.slider(1, 10, value=7),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Angela",
+ "last_name": "Martin",
+ "skill": mo.ui.slider(1, 10, value=5),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Kevin",
+ "last_name": "Malone",
+ "skill": mo.ui.slider(1, 10, value=3),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Oscar",
+ "last_name": "Martinez",
+ "skill": mo.ui.slider(1, 10, value=3),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Stanley",
+ "last_name": "Hudson",
+ "skill": mo.ui.slider(1, 10, value=5),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Phyllis",
+ "last_name": "Vance",
+ "skill": mo.ui.slider(1, 10, value=5),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Meredith",
+ "last_name": "Palmer",
+ "skill": mo.ui.slider(1, 10, value=7),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Creed",
+ "last_name": "Bratton",
+ "skill": mo.ui.slider(1, 10, value=3),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Ryan",
+ "last_name": "Howard",
+ "skill": mo.ui.slider(1, 10, value=5),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Kelly",
+ "last_name": "Kapoor",
+ "skill": mo.ui.slider(1, 10, value=3),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Toby",
+ "last_name": "Flenderson",
+ "skill": mo.ui.slider(1, 10, value=3),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Darryl",
+ "last_name": "Philbin",
+ "skill": mo.ui.slider(1, 10, value=7),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Erin",
+ "last_name": "Hannon",
+ "skill": mo.ui.slider(1, 10, value=5),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Andy",
+ "last_name": "Bernard",
+ "skill": mo.ui.slider(1, 10, value=5),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Jan",
+ "last_name": "Levinson",
+ "skill": mo.ui.slider(1, 10, value=5),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "David",
+ "last_name": "Wallace",
+ "skill": mo.ui.slider(1, 10, value=3),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ {
+ "first_name": "Holly",
+ "last_name": "Flax",
+ "skill": mo.ui.slider(1, 10, value=7),
+ "favorite place": mo.image(src="https://picsum.photos/100"),
+ },
+ ]
+ return (office_characters,)
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/tabs.py b/examples/ui/tabs.py
index 003aa87e58..d3aa3b8da6 100644
--- a/examples/ui/tabs.py
+++ b/examples/ui/tabs.py
@@ -1,74 +1,29 @@
-# /// script
-# requires-python = ">=3.9"
-# dependencies = [
-# "marimo",
-# ]
-# ///
-
import marimo
-__generated_with = "0.8.19"
+__generated_with = "0.10.6"
app = marimo.App()
[email protected](hide_code=True)
-def __(mo):
- mo.md("""# Tabs""")
- return
-
-
[email protected](hide_code=True)
-def __(mo):
- mo.md("""Use `mo.ui.tabs` to organize outputs.""")
- return
-
-
@app.cell
-def __(mo):
- settings = mo.vstack(
- [
- mo.md("Edit User"),
- first := mo.ui.text(label="First Name"),
- last := mo.ui.text(label="Last Name"),
- ]
- )
-
- organization = mo.vstack(
- [
- mo.md("Edit Organization"),
- org := mo.ui.text(label="Organization Name", value="..."),
- employees := mo.ui.number(
- label="Number of Employees", start=0, stop=1000
- ),
- ]
- )
-
- mo.ui.tabs(
- {
- "🧙‍♀ User": settings,
- "🏢 Organization": organization,
- }
- )
- return employees, first, last, org, organization, settings
+def _():
+ import marimo as mo
+ return (mo,)
@app.cell
-def __(employees, first, last, mo, org):
- mo.md(
- f"""
- Welcome **{first.value} {last.value}** to **{org.value}**! You are
- employee no. **{employees.value + 1}**.
-
- #{"🎉" * (min(employees.value + 1, 1000))}
- """
- ) if all([first.value, last.value, org.value]) else None
- return
+def _(mo):
+ tabs = mo.ui.tabs({
+ "Bob says": mo.md("Hello, Alice! 👋"),
+ "Alice says": mo.md("Hello, Bob! 👋")
+ })
+ tabs
+ return (tabs,)
@app.cell
-def __():
- import marimo as mo
- return (mo,)
+def _(tabs):
+ tabs.value
+ return
if __name__ == "__main__":
diff --git a/examples/ui/tabs_advanced.py b/examples/ui/tabs_advanced.py
new file mode 100644
index 0000000000..8dd01fa376
--- /dev/null
+++ b/examples/ui/tabs_advanced.py
@@ -0,0 +1,77 @@
+# /// script
+# requires-python = ">=3.9"
+# dependencies = [
+# "marimo",
+# ]
+# ///
+
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App()
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
[email protected](hide_code=True)
+def _(mo):
+ mo.md("""# Tabs""")
+ return
+
+
[email protected](hide_code=True)
+def _(mo):
+ mo.md("""Use `mo.ui.tabs` to organize outputs.""")
+ return
+
+
+def _(mo):
+ settings = mo.vstack(
+ [
+ mo.md("Edit User"),
+ first := mo.ui.text(label="First Name"),
+ last := mo.ui.text(label="Last Name"),
+ ]
+ )
+
+ organization = mo.vstack(
+ [
+ mo.md("Edit Organization"),
+ org := mo.ui.text(label="Organization Name", value="..."),
+ employees := mo.ui.number(
+ label="Number of Employees", start=0, stop=1000
+ ),
+ ]
+ )
+
+ mo.ui.tabs(
+ {
+ "🧙‍♀ User": settings,
+ "🏢 Organization": organization,
+ }
+ )
+ return employees, first, last, org, organization, settings
+
+
+def _(employees, first, last, mo, org):
+ mo.md(
+ f"""
+ Welcome **{first.value} {last.value}** to **{org.value}**! You are
+ employee no. **{employees.value + 1}**.
+
+ #{"🎉" * (min(employees.value + 1, 1000))}
+ """
+ ) if all([first.value, last.value, org.value]) else mo.md(
+ "Type a first and last name!"
+ )
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/text.py b/examples/ui/text.py
new file mode 100644
index 0000000000..6054bc2f1b
--- /dev/null
+++ b/examples/ui/text.py
@@ -0,0 +1,27 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App()
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ text = mo.ui.text()
+ text
+ return (text,)
+
+
+def _(text):
+ text.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ui/text_area.py b/examples/ui/text_area.py
new file mode 100644
index 0000000000..8c5b432f52
--- /dev/null
+++ b/examples/ui/text_area.py
@@ -0,0 +1,27 @@
+import marimo
+
+__generated_with = "0.10.6"
+app = marimo.App()
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ text_area = mo.ui.text_area(placeholder="type some text ...")
+ text_area
+ return (text_area,)
+
+
+def _(text_area):
+ text_area.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/marimo/_tutorials/ui.py b/marimo/_tutorials/ui.py
index 261c25bda5..a414c0fa80 100644
--- a/marimo/_tutorials/ui.py
+++ b/marimo/_tutorials/ui.py
@@ -2,12 +2,12 @@
import marimo
-__generated_with = "0.9.14"
+__generated_with = "0.10.6"
app = marimo.App()
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
# UI Elements
@@ -21,13 +21,13 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md("""## marimo.ui""")
return
@app.cell
-def __(mo):
+def _(mo):
slider = mo.ui.slider(start=1, stop=10, step=1)
slider
@@ -42,13 +42,13 @@ def __(mo):
@app.cell
-def __(mo, slider):
+def _(mo, slider):
mo.md(f"and here's its value: **{slider.value}**.")
return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
### How interactions run cells
@@ -66,7 +66,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo, slider):
+def _(mo, slider):
mo.accordion(
{
"Tip: assign UI elements to global variables": (
@@ -95,135 +95,146 @@ def __(mo, slider):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md("""### Simple elements""")
return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md("""marimo has a [large library of simple UI elements](https://docs.marimo.io/api/inputs/index.html). Here are a just few examples:""")
return
[email protected](hide_code=True)
+def _(mo):
+ mo.md(
+ """
+ See our [examples folder](https://github.com/marimo-team/marimo/tree/main/examples/ui) on GitHub for bite-sized notebooks showcasing all our UI elements. For
+ a more detailed reference, see our [API docs](https://docs.marimo.io/api/inputs/).
+ """
+ ).callout()
+ return
+
+
@app.cell
-def __(mo):
+def _(mo):
number = mo.ui.number(start=1, stop=10, step=1)
number
return (number,)
@app.cell
-def __(number):
+def _(number):
number.value
return
@app.cell
-def __(mo):
+def _(mo):
checkbox = mo.ui.checkbox(label="checkbox")
checkbox
return (checkbox,)
@app.cell
-def __(checkbox):
+def _(checkbox):
checkbox.value
return
@app.cell
-def __(mo):
+def _(mo):
text = mo.ui.text(placeholder="type some text ...")
text
return (text,)
@app.cell
-def __(text):
+def _(text):
text.value
return
@app.cell
-def __(mo):
+def _(mo):
text_area = mo.ui.text_area(placeholder="type some text ...")
text_area
return (text_area,)
@app.cell
-def __(text_area):
+def _(text_area):
text_area.value
return
@app.cell
-def __(mo):
+def _(mo):
dropdown = mo.ui.dropdown(["a", "b", "c"])
dropdown
return (dropdown,)
@app.cell
-def __(dropdown):
+def _(dropdown):
dropdown.value
return
@app.cell
-def __(mo):
+def _(mo):
run_button = mo.ui.run_button(label="click me")
run_button
return (run_button,)
@app.cell
-def __(run_button):
+def _(run_button):
"Run button was clicked!" if run_button.value else "Click the run button!"
return
@app.cell
-def __(mo):
+def _(mo):
file_upload = mo.ui.file(kind="area")
file_upload
return (file_upload,)
@app.cell
-def __(file_upload):
+def _(file_upload):
file_upload.value
return
@app.cell
-def __(basic_ui_elements, mo):
+def _(basic_ui_elements, mo):
mo.md(f"To see more examples, use this dropdown: {basic_ui_elements}")
return
@app.cell
-def __(basic_ui_elements, construct_element, show_element):
+def _(basic_ui_elements, construct_element, show_element):
selected_element = construct_element(basic_ui_elements.value)
show_element(selected_element)
return (selected_element,)
@app.cell
-def __(selected_element, value):
+def _(selected_element, value):
value(selected_element)
return
@app.cell
-def __(basic_ui_elements, documentation):
+def _(basic_ui_elements, documentation):
documentation(basic_ui_elements.value)
return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
### Composite elements
@@ -240,7 +251,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
This first example shows how to create an array of UI elements using `mo.ui.array`.
@@ -252,7 +263,7 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
array = mo.ui.array(
[mo.ui.text(), mo.ui.slider(start=1, stop=10), mo.ui.date()]
)
@@ -261,19 +272,19 @@ def __(mo):
@app.cell
-def __(array):
+def _(array):
array.value
return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(r"""marimo also comes with `mo.ui.dictionary`, which is analogous to `mo.ui.array`""")
return
@app.cell
-def __(mo):
+def _(mo):
dictionary = mo.ui.dictionary(
{
"text": mo.ui.text(),
@@ -286,13 +297,13 @@ def __(mo):
@app.cell
-def __(dictionary):
+def _(dictionary):
dictionary.value
return
@app.cell(hide_code=True)
-def __(composite_elements, mo):
+def _(composite_elements, mo):
mo.md(
f"To see additional composite elements, use this dropdown: {composite_elements}"
)
@@ -300,26 +311,26 @@ def __(composite_elements, mo):
@app.cell
-def __(composite_elements, construct_element, show_element):
+def _(composite_elements, construct_element, show_element):
composite_element = construct_element(composite_elements.value)
show_element(composite_element)
return (composite_element,)
@app.cell
-def __(composite_element, value):
+def _(composite_element, value):
value(composite_element)
return
@app.cell
-def __(composite_elements, documentation):
+def _(composite_elements, documentation):
documentation(composite_elements.value)
return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
### Building custom elements
@@ -334,7 +345,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
## Appendix
@@ -347,7 +358,7 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
composite_elements = mo.ui.dropdown(
options=dict(
sorted(
@@ -365,7 +376,7 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
basic_ui_elements = mo.ui.dropdown(
options=dict(
sorted(
@@ -393,7 +404,7 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
def construct_element(value):
if value == mo.ui.array:
return mo.ui.array(
@@ -476,7 +487,7 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
def show_element(element):
if element is not None:
return mo.hstack([element], justify="center")
@@ -484,7 +495,7 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
def value(element):
if element is not None:
v = (
@@ -501,7 +512,7 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
def documentation(element):
if element is not None:
return mo.accordion(
@@ -515,7 +526,7 @@ def __(mo):
@app.cell
-def __():
+def _():
import marimo as mo
return (mo,)