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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
docs: usage examples (#4530)
Akshay Agrawala1a95d1d5616
diff --git a/docs/_static/example-thumbs/Screenshot 2025-04-15 at 8.15.03 AM.png b/docs/_static/example-thumbs/Screenshot 2025-04-15 at 8.15.03 AM.pngnew file mode 100644index 0000000000..a620e5fb73Binary files /dev/null and b/docs/_static/example-thumbs/Screenshot 2025-04-15 at 8.15.03 AM.png differdiff --git a/docs/_static/example-thumbs/accordion.png b/docs/_static/example-thumbs/accordion.pngnew file mode 100644index 0000000000..9ed3d4af9eBinary files /dev/null and b/docs/_static/example-thumbs/accordion.png differdiff --git a/docs/_static/example-thumbs/admonitions.png b/docs/_static/example-thumbs/admonitions.pngnew file mode 100644index 0000000000..763e2496efBinary files /dev/null and b/docs/_static/example-thumbs/admonitions.png differdiff --git a/docs/_static/example-thumbs/altair.png b/docs/_static/example-thumbs/altair.pngnew file mode 100644index 0000000000..ff3fa61eceBinary files /dev/null and b/docs/_static/example-thumbs/altair.png differdiff --git a/docs/_static/example-thumbs/array.png b/docs/_static/example-thumbs/array.pngnew file mode 100644index 0000000000..f7efa26499Binary files /dev/null and b/docs/_static/example-thumbs/array.png differdiff --git a/docs/_static/example-thumbs/chat.png b/docs/_static/example-thumbs/chat.pngnew file mode 100644index 0000000000..112553b021Binary files /dev/null and b/docs/_static/example-thumbs/chat.png differdiff --git a/docs/_static/example-thumbs/checkbox.png b/docs/_static/example-thumbs/checkbox.pngnew file mode 100644index 0000000000..0cf3191e73Binary files /dev/null and b/docs/_static/example-thumbs/checkbox.png differdiff --git a/docs/_static/example-thumbs/code_editor.png b/docs/_static/example-thumbs/code_editor.pngnew file mode 100644index 0000000000..fd7e460869Binary files /dev/null and b/docs/_static/example-thumbs/code_editor.png differdiff --git a/docs/_static/example-thumbs/dataframe_transformer.png b/docs/_static/example-thumbs/dataframe_transformer.pngnew file mode 100644index 0000000000..5e3ff7555cBinary files /dev/null and b/docs/_static/example-thumbs/dataframe_transformer.png differdiff --git a/docs/_static/example-thumbs/dataframes.png b/docs/_static/example-thumbs/dataframes.pngnew file mode 100644index 0000000000..1d3c60f366Binary files /dev/null and b/docs/_static/example-thumbs/dataframes.png differdiff --git a/docs/_static/example-thumbs/date.png b/docs/_static/example-thumbs/date.pngnew file mode 100644index 0000000000..b4a32360f4Binary files /dev/null and b/docs/_static/example-thumbs/date.png differdiff --git a/docs/_static/example-thumbs/details.png b/docs/_static/example-thumbs/details.pngnew file mode 100644index 0000000000..ad861cb2d7Binary files /dev/null and b/docs/_static/example-thumbs/details.png differdiff --git a/docs/_static/example-thumbs/dictionary.png b/docs/_static/example-thumbs/dictionary.pngnew file mode 100644index 0000000000..15c4d2716fBinary files /dev/null and b/docs/_static/example-thumbs/dictionary.png differdiff --git a/docs/_static/example-thumbs/dropdown.png b/docs/_static/example-thumbs/dropdown.pngnew file mode 100644index 0000000000..837937d47fBinary files /dev/null and b/docs/_static/example-thumbs/dropdown.png differdiff --git a/docs/_static/example-thumbs/dynamic_markdown.png b/docs/_static/example-thumbs/dynamic_markdown.pngnew file mode 100644index 0000000000..0584403261Binary files /dev/null and b/docs/_static/example-thumbs/dynamic_markdown.png differdiff --git a/docs/_static/example-thumbs/editable_dataframes.png b/docs/_static/example-thumbs/editable_dataframes.pngnew file mode 100644index 0000000000..aa3e83a99bBinary files /dev/null and b/docs/_static/example-thumbs/editable_dataframes.png differdiff --git a/docs/_static/example-thumbs/file_upload.png b/docs/_static/example-thumbs/file_upload.pngnew file mode 100644index 0000000000..c990cd0a4fBinary files /dev/null and b/docs/_static/example-thumbs/file_upload.png differdiff --git a/docs/_static/example-thumbs/form.png b/docs/_static/example-thumbs/form.pngnew file mode 100644index 0000000000..20782e13e6Binary files /dev/null and b/docs/_static/example-thumbs/form.png differdiff --git a/docs/_static/example-thumbs/mermaid.png b/docs/_static/example-thumbs/mermaid.pngnew file mode 100644index 0000000000..5776d57973Binary files /dev/null and b/docs/_static/example-thumbs/mermaid.png differdiff --git a/docs/_static/example-thumbs/microphone.png b/docs/_static/example-thumbs/microphone.pngnew file mode 100644index 0000000000..ad5847f36aBinary files /dev/null and b/docs/_static/example-thumbs/microphone.png differdiff --git a/docs/_static/example-thumbs/multiselect.png b/docs/_static/example-thumbs/multiselect.pngnew file mode 100644index 0000000000..e4f9b4d66dBinary files /dev/null and b/docs/_static/example-thumbs/multiselect.png differdiff --git a/docs/_static/example-thumbs/number.png b/docs/_static/example-thumbs/number.pngnew file mode 100644index 0000000000..8f229de286Binary files /dev/null and b/docs/_static/example-thumbs/number.png differdiff --git a/docs/_static/example-thumbs/plotly.png b/docs/_static/example-thumbs/plotly.pngnew file mode 100644index 0000000000..b178588a78Binary files /dev/null and b/docs/_static/example-thumbs/plotly.png differdiff --git a/docs/_static/example-thumbs/progress_bar.png b/docs/_static/example-thumbs/progress_bar.pngnew file mode 100644index 0000000000..550bfaaaf3Binary files /dev/null and b/docs/_static/example-thumbs/progress_bar.png differdiff --git a/docs/_static/example-thumbs/radio.png b/docs/_static/example-thumbs/radio.pngnew file mode 100644index 0000000000..b3e52dbadbBinary files /dev/null and b/docs/_static/example-thumbs/radio.png differdiff --git a/docs/_static/example-thumbs/run_button.png b/docs/_static/example-thumbs/run_button.pngnew file mode 100644index 0000000000..e9081b4a59Binary files /dev/null and b/docs/_static/example-thumbs/run_button.png differdiff --git a/docs/_static/example-thumbs/slider.png b/docs/_static/example-thumbs/slider.pngnew file mode 100644index 0000000000..6514a6cc09Binary files /dev/null and b/docs/_static/example-thumbs/slider.png differdiff --git a/docs/_static/example-thumbs/spinner.png b/docs/_static/example-thumbs/spinner.pngnew file mode 100644index 0000000000..a4980cfd8aBinary files /dev/null and b/docs/_static/example-thumbs/spinner.png differdiff --git a/docs/_static/example-thumbs/stacks.png b/docs/_static/example-thumbs/stacks.pngnew file mode 100644index 0000000000..f3b0966cdaBinary files /dev/null and b/docs/_static/example-thumbs/stacks.png differdiff --git a/docs/_static/example-thumbs/tables.png b/docs/_static/example-thumbs/tables.pngnew file mode 100644index 0000000000..84ea11212fBinary files /dev/null and b/docs/_static/example-thumbs/tables.png differdiff --git a/docs/_static/example-thumbs/tabs.png b/docs/_static/example-thumbs/tabs.pngnew file mode 100644index 0000000000..b9138a71d4Binary files /dev/null and b/docs/_static/example-thumbs/tabs.png differdiff --git a/docs/_static/example-thumbs/text.png b/docs/_static/example-thumbs/text.pngnew file mode 100644index 0000000000..672c6aa415Binary files /dev/null and b/docs/_static/example-thumbs/text.png differdiff --git a/docs/_static/example-thumbs/text_area.png b/docs/_static/example-thumbs/text_area.pngnew file mode 100644index 0000000000..d12315420cBinary files /dev/null and b/docs/_static/example-thumbs/text_area.png differdiff --git a/docs/api/inputs/data_editor.md b/docs/api/inputs/data_editor.mdnew file mode 100644index 0000000000..cb6457bb74--- /dev/null+++ b/docs/api/inputs/data_editor.md@@ -0,0 +1,8 @@+# Data editor++/// marimo-embed-file+ size: xlarge+ filepath: examples/ui/data_editor.py+///++::: marimo.ui.data_editordiff --git a/docs/api/inputs/tabs.md b/docs/api/inputs/tabs.mdindex c28852de4c..caa85b0986 100644--- a/docs/api/inputs/tabs.md+++ b/docs/api/inputs/tabs.md@@ -1,45 +1,9 @@# Tabs-/// marimo-embed+/// marimo-embed-filesize: large--```python-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")- def simple_echo_model(messages, config):- return f"You said: {messages[-1].content}"-- chat = mo.ui.chat(- simple_echo_model,- prompts=["Hello", "How are you?"],- show_configuration_controls=True- )- None- return--def __():- mo.ui.tabs(- {- "📈 Sales": bar,- "📊 Chatbot": chat,- "💻 Settings": mo.ui.text(placeholder="Key"),- }- )- return-```-+ mode: edit+ filepath: examples/ui/tabs.py///::: marimo.ui.tabsdiff --git a/docs/api/layouts/accordion.md b/docs/api/layouts/accordion.mdindex 9095fc7f10..acf30188ac 100644--- a/docs/api/layouts/accordion.md+++ b/docs/api/layouts/accordion.md@@ -1,23 +1,9 @@# Accordion-/// marimo-embed+/// marimo-embed-filesize: medium--```python-def __():- mo.accordion(- {- "Door 1": mo.md("Nothing!"),- "Door 2": mo.md("Nothing!"),- "Door 3": mo.md(- ""- ),- }- )- return-```-+ mode: edit+ filepath: examples/outputs/accordion.py///::: marimo.accordiondiff --git a/docs/api/status.md b/docs/api/status.mdindex 499728e139..1f0714d7fa 100644--- a/docs/api/status.md+++ b/docs/api/status.md@@ -9,59 +9,18 @@ databases, or APIs.You can display a progress bar while iterating over a collection, similarto `tqdm`.-/// marimo-embed+/// marimo-embed-filesize: medium--```python-def __():- rerun = mo.ui.button(label="Rerun")- rerun- return--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-```-+ filepath: examples/outputs/progress_bar.py///::: marimo.status.progress_bar## Spinner-/// marimo-embed+/// marimo-embed-filesize: medium--```python-def __():- rerun = mo.ui.button(label="Rerun")- rerun- return--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-```-+ filepath: examples/outputs/spinner.py///::: marimo.status.spinnerdiff --git a/docs/blocks.py b/docs/blocks.pyindex c8fc182c02..d89ff19158 100644--- a/docs/blocks.py+++ b/docs/blocks.py@@ -4,7 +4,7 @@ from typing import Any, Dict, List, Union, castimport urllib.parsefrom pymdownx.blocks import BlocksExtension # type: ignore-from pymdownx.blocks.block import Block, type_string, type_string_in # type: ignore+from pymdownx.blocks.block import Block, type_boolean, type_string, type_string_in # type: ignoreclass BaseMarimoBlock(Block):@@ -15,7 +15,8 @@ class BaseMarimoBlock(Block):"medium",type_string_in(["small", "medium", "large", "xlarge", "xxlarge"]),],- "mode": ["read", type_string_in(["read", "edit"])],+ "mode": ["edit", type_string_in(["read", "edit"])],+ "show-chrome": [False, type_boolean],}def on_create(self, parent: etree.Element) -> etree.Element:@@ -66,9 +67,12 @@ class MarimoEmbedBlock(BaseMarimoBlock):app_width: str = cast(str, self.options["app_width"])mode: str = cast(str, self.options["mode"])+ show_chrome: bool = cast(bool, self.options["show-chrome"])url = create_marimo_app_url(code=create_marimo_app_code(code=code, app_width=app_width),mode=mode,+ show_chrome=show_chrome,+)self._create_iframe(block, url)@@ -94,7 +98,8 @@ class MarimoEmbedFileBlock(BaseMarimoBlock):raise ValueError(f"File not found: {filepath}")mode: str = cast(str, self.options["mode"])- url = create_marimo_app_url(code=code, mode=mode)+ show_chrome: bool = cast(bool, self.options["show-chrome"])+ url = create_marimo_app_url(code=code, mode=mode, show_chrome=show_chrome)self._create_iframe(block, url)# Add source code section if enabled@@ -146,9 +151,9 @@ def create_marimo_app_code(return header + code-def create_marimo_app_url(code: str, mode: str = "read") -> str:+def create_marimo_app_url(code: str, mode: str = "edit", show_chrome: bool = False) -> str:encoded_code = uri_encode_component(code)- return f"https://marimo.app/?code={encoded_code}&embed=true&mode={mode}"+ return f'https://marimo.app/?code={encoded_code}&embed=true&mode={mode}&show-chrome={"true" if show_chrome else "false"}'class MarimoBlocksExtension(BlocksExtension):diff --git a/docs/examples.md b/docs/examples.mddeleted file mode 100644index 6b90e3c07f..0000000000--- a/docs/examples.md+++ /dev/null@@ -1,12 +0,0 @@-# Examples--We have a large [library of-examples](https://github.com/marimo-team/marimo/tree/main/examples) in our-repo. Each example [encapsulates its own Python dependencies in a package-sandbox](guides/editor_features/package_management.md), making it easy to run.-We've deployed some of these examples at our [public-gallery](https://marimo.io/@public).--We spotlight projects from the community each week on [our Twitter](https://x.com/marimo_io); check out our-[spotlights repo](https://github.com/marimo-team/spotlights) for a running-archive, with links to notebooks.diff --git a/docs/examples/index.md b/docs/examples/index.mdnew file mode 100644index 0000000000..d14bf59a64--- /dev/null+++ b/docs/examples/index.md@@ -0,0 +1,323 @@+# Examples++This page includes dozens of bite-sized how-to examples to help you get started+with marimo. Be sure to also read the [quickstart](../getting_started/index.md) and+the [user guide](../guides/index.md), especially the guide on [how marimo runs+cells](../guides/reactivity.md).++!!! Tip "Get inspired at our gallery!"++ For inspirational examples, including embedding-driven+ data labelers, Stanford-scientist authored tutorials, and more,+ check out our [public gallery](https://marimo.io/gallery).+++## Running cells++<div class="grid cards" markdown>++- ⚡️ [**Basic execution**](running_cells/basics.md)++- 🐞 [**Getting around multiple definition errors**](running_cells/multiple_definitions.md)++- 🛑 [**Stop cells from running**](running_cells/stop.md)++- 🖱️ [**Run cells on button click**](running_cells/run_button.md)++- 🕓 [**Refresh on a timer**](running_cells/refresh.md)++- ⏳ [**Run async functions**](running_cells/async_await.md)++- 💾 [**Caching computations in memory**](running_cells/memory_cache.md)++- 💾 [**Cache computations to persistent storage**](running_cells/persistent_cache.md)++- 🐞 [**Using the debugger**](running_cells/debugging.md)++</div>++## Visual Outputs++<div class="grid cards" markdown>++- 📤 [**Cell outputs**](outputs/basic_output.md)++- ✍️ [**Basic markdown**](outputs/basic_markdown.md)++- 💬 [**Console outputs**](outputs/console_outputs.md)++- 📋 [**Capturing console output**](outputs/capture_console_outputs.md)++- 📈 [**Showing plots**](outputs/plots.md)++- 🎥 [**Showing videos and other media**](../api/media/index.md)++- 🎛️ [**Conditionally showing outputs**](outputs/conditional_output.md)++- 🧩 [**Showing multiple outputs in one cell**](outputs/multiple_outputs.md)++</div>++### Writing markdown++<div class="grid cards examples-grid" markdown>++- ⚡️ [**Python values in markdown**](markdown/dynamic_markdown.md)++ ---++ <a href="markdown/dynamic_markdown.md"><img src="/_static/example-thumbs/dynamic_markdown.png" /></a>++- 🪄 [**Mermaid diagrams**](markdown/mermaid.md)++ ---++ <a href="markdown/mermaid.md"><img src="/_static/example-thumbs/mermaid.png" /></a>++- 🚨 [**Admonitions**](markdown/admonitions.md)++ ---++ <a href="markdown/admonitions.md"><img src="/_static/example-thumbs/admonitions.png" /></a>++- 📂 [**Collapsible details**](markdown/details.md)++ ---++ <a href="markdown/details.md"><img src="/_static/example-thumbs/details.png" /></a>++- 😀 [**Emoji**](markdown/emoji.md)++</div>++## Working with data++### Dataframes++marimo is designed for working with dataframes. Here are a few examples; see+the [dataframes guide](../guides/working_with_data/dataframes.md) for details.++<div class="grid cards" markdown>++- 🧮 [**Interactive dataframe viewer**](outputs/dataframes.md)++ ---++ <a href="outputs/dataframes.md"><img src="/_static/example-thumbs/dataframes.png" /></a>++- 🔍 [**Select dataframe rows**](../api/inputs/table.md)++ ---++ <a href="../api/inputs/table.md"><img src="/_static/example-thumbs/tables.png" /></a>++- ✏️ [**Editable dataframe**](../api/inputs/data_editor.md)++ ---++ <a href="api/inputs/data_editor.md"><img src="/_static/example-thumbs/editable_dataframes.png" /></a>++- 🛠️ [**Interactive dataframe transformer**](../api/inputs/dataframe.md)++ ---++ <a href="api/inputs/dataframe.md"><img src="/_static/example-thumbs/dataframe_transformer.png" /></a>++</div>++### SQL++Here are some basic examples, see the [SQL+guide](../guides/working_with_data/sql.md) for more details.++<div class="grid cards examples-grid" markdown>++- 🦆 [**Query dataframes with DuckDB SQL**](../guides/working_with_data/sql.md#example)++- 🛢️ [**SQLite, Postgres, and other engines**](../guides/working_with_data/sql.md#connecting-to-a-custom-database)++</div>++### Plots++See the [plotting guide](../guides/working_with_data/plotting.md) for a full+overview.++<div class="grid cards examples-grid" markdown>++- 📊 [**Selecting data with Altair**](../api/plotting.md#reactive-charts-with-altair)++ ---++ <a href="../api/plotting.md#reactive-charts-with-altair"><img src="/_static/example-thumbs/altair.png" /></a>++- 📉 [**Selecting data with Plotly**](../guides/working_with_data/plotting.md#plotly)++ ---++ <a href="../guides/working_with_data/plotting.md#Plotly"><img src="/_static/example-thumbs/plotly.png" /></a>++- 🔭 [**Showing matplotlib plots**](outputs/plots.md)++</div>++### Progress bars and status elements++<div class="grid cards examples-grid" markdown>++- 📶 [**Progress bar**](outputs/progress_bar.md)++ ---++ <a href=outputs/progress_bar.md"><img src="/_static/example-thumbs/progress_bar.png" /></a>++- 🌀 [**Loading spinner**](outputs/spinner.md)++ ---++ <a href=outputs/spinner.md"><img src="/_static/example-thumbs/spinner.png" /></a>++</div>+++### Layouts++<div class="grid cards examples-grid" markdown>++- 📐 [**Horizontal and vertical stacking**](outputs/stacks.md)++ ---++ <a href=outputs/stacks.md"><img src="/_static/example-thumbs/stacks.png" /></a>++- 📁 [**Accordion toggle**](../api/layouts/accordion.md)++ ---++ <a href="../api/layouts/accordion.md"><img src="/_static/example-thumbs/accordion.png" /></a>++- 🗂️ [**Tabs**](../api/inputs/tabs.md)++ ---++ <a href="../api/inputs/tabs.md"><img src="/_static/example-thumbs/tabs.png" /></a>++</div>++## Input elements++### Basic input elements++marimo has a large library of interactive UI elements, which you can use+without callbacks — just make sure to assign elements to global variables. See+the [API reference](../api/inputs/index.md) for a full list, and the [interactivity+guide](../guides/interactivity.md) for rules governing how UI elements work.++<div class="grid cards examples-grid" markdown>++- 🎚️ [**Slider**](../api/inputs/slider.md)++ ---++ <a href="../api/inputs/slider.md"><img src="/_static/example-thumbs/slider.png" /></a>++- 🧾 [**Dropdown**](../api/inputs/dropdown.md)++ ---++ <a href="../api/inputs/dropdown.md"><img src="/_static/example-thumbs/dropdown.png" /></a>++- 👆 [**Multi-select**](../api/inputs/multiselect.md)++ ---++ <a href="../api/inputs/multiselect.md"><img src="/_static/example-thumbs/multiselect.png" /></a>++- 🔘 [**Radio buttons**](../api/inputs/radio.md)++ ---++ <a href="../api/inputs/radio.md"><img src="/_static/example-thumbs/radio.png" /></a>++- ☑️ [**Checkbox**](../api/inputs/checkbox.md)++ ---++ <a href="../api/inputs/checkbox.md"><img src="/_static/example-thumbs/checkbox.png" /></a>++- 📅 [**Date**](../api/inputs/dates.md)++ ---++ <a href="../api/inputs/date.md"><img src="/_static/example-thumbs/date.png" /></a>++- 📁 [**File**](../api/inputs/file.md)++ ---++ <a href="../api/inputs/file.md"><img src="/_static/example-thumbs/file_upload.png" /></a>++- 🔤 [**Text input**](../api/inputs/text.md)++ ---++ <a href="../api/inputs/text.md"><img src="/_static/example-thumbs/text.png" /></a>++- 📝 [**Text area**](../api/inputs/text_area.md)++ ---++ <a href="../api/inputs/text_area.md"><img src="/_static/example-thumbs/text_area.png" /></a>++- 🧑💻 [**Code editor**](../api/inputs/code_editor.md)++ ---++ <a href="../api/inputs/code_editor.md"><img src="/_static/example-thumbs/code_editor.png" /></a>++- 🔍 [**Table**](../api/inputs/table.md)++ ---++ <a href="../api/inputs/table.md"><img src="/_static/example-thumbs/tables.png" /></a>++- 🎙️ [**Microphone**](../api/inputs/microphone.md)++ ---++ <a href="../api/inputs/microphone.md"><img src="/_static/example-thumbs/microphone.png" /></a>++- 💬 [**Chat**](../api/inputs/chat.md)++ ---++ <a href="../api/inputs/chat.md"><img src="/_static/example-thumbs/chat.png" /></a>++</div>++### Composite input elements++Composite input elements let you create a single UI element from multiple+other UI elements.++<div class="grid cards examples-grid" markdown>++- 🧾 [**Form**](../api/inputs/form.md)++ ---++ <a href="../api/inputs/form.md"><img src="/_static/example-thumbs/form.png" /></a>++- 🎒 [**Array**](../api/inputs/array.md)++ ---++ <a href="../api/inputs/array.md"><img src="/_static/example-thumbs/array.png" /></a>++- 📖 [**Dictionary**](../api/inputs/dictionary.md)++ ---++ <a href="../api/inputs/dictionary.md"><img src="/_static/example-thumbs/dictionary.png" /></a>++</div>diff --git a/docs/examples/markdown/admonitions.md b/docs/examples/markdown/admonitions.mdnew file mode 100644index 0000000000..508857e9e1--- /dev/null+++ b/docs/examples/markdown/admonitions.md@@ -0,0 +1,8 @@+# Admonitions+++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/markdown/admonitions.py+///diff --git a/docs/examples/markdown/details.md b/docs/examples/markdown/details.mdnew file mode 100644index 0000000000..dd9c67cbdc--- /dev/null+++ b/docs/examples/markdown/details.md@@ -0,0 +1,8 @@+# Details+++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/markdown/details.py+///diff --git a/docs/examples/markdown/dynamic_markdown.md b/docs/examples/markdown/dynamic_markdown.mdnew file mode 100644index 0000000000..496d40cad0--- /dev/null+++ b/docs/examples/markdown/dynamic_markdown.md@@ -0,0 +1,7 @@+# Dynamic markdown++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/markdown/dynamic_markdown.py+///diff --git a/docs/examples/markdown/emoji.md b/docs/examples/markdown/emoji.mdnew file mode 100644index 0000000000..300446c54d--- /dev/null+++ b/docs/examples/markdown/emoji.md@@ -0,0 +1,8 @@+# Emoji+++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/markdown/emoji.py+///diff --git a/docs/examples/markdown/mermaid.md b/docs/examples/markdown/mermaid.mdnew file mode 100644index 0000000000..19070057f5--- /dev/null+++ b/docs/examples/markdown/mermaid.md@@ -0,0 +1,8 @@+# Mermaid+++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/markdown/mermaid.py+///diff --git a/docs/examples/outputs/basic_markdown.md b/docs/examples/outputs/basic_markdown.mdnew file mode 100644index 0000000000..67b8c3f2e2--- /dev/null+++ b/docs/examples/outputs/basic_markdown.md@@ -0,0 +1,10 @@+# Basic markdown++marimo has [built-in support for markdown](../../guides/outputs.md#markdown).+The simplest way to write markdown is to use markdown cells.++/// marimo-embed-file+ size: xxlarge+ mode: edit+ filepath: examples/outputs/basic_markdown.py+///diff --git a/docs/examples/outputs/basic_output.md b/docs/examples/outputs/basic_output.mdnew file mode 100644index 0000000000..c9c613c828--- /dev/null+++ b/docs/examples/outputs/basic_output.md@@ -0,0 +1,7 @@+# Cell output++/// marimo-embed-file+ size: xxlarge+ mode: edit+ filepath: examples/outputs/cell_output.py+///diff --git a/docs/examples/outputs/capture_console_outputs.md b/docs/examples/outputs/capture_console_outputs.mdnew file mode 100644index 0000000000..2727a29d1f--- /dev/null+++ b/docs/examples/outputs/capture_console_outputs.md@@ -0,0 +1,10 @@+# Capture console outputs++You can capture console outputs with marimo utility functions. Learn+more in the [API reference](https://docs.marimo.io/api/outputs/#console-outputs).++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/outputs/capture_console_outputs.py+///diff --git a/docs/examples/outputs/conditional_output.md b/docs/examples/outputs/conditional_output.mdnew file mode 100644index 0000000000..1b5df771ed--- /dev/null+++ b/docs/examples/outputs/conditional_output.md@@ -0,0 +1,8 @@+# Conditionally showing outputs+++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/outputs/conditional_output.py+///diff --git a/docs/examples/outputs/console_outputs.md b/docs/examples/outputs/console_outputs.mdnew file mode 100644index 0000000000..f723ab6d41--- /dev/null+++ b/docs/examples/outputs/console_outputs.md@@ -0,0 +1,7 @@+# Console outputs++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/outputs/console_outputs.py+///diff --git a/docs/examples/outputs/dataframes.md b/docs/examples/outputs/dataframes.mdnew file mode 100644index 0000000000..5103ad69e4--- /dev/null+++ b/docs/examples/outputs/dataframes.md@@ -0,0 +1,9 @@+# Dataframes++See the [dataframes guide](../../guides/working_with_data/dataframes.md) for more info.++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/outputs/dataframes.py+///diff --git a/docs/examples/outputs/multiple_outputs.md b/docs/examples/outputs/multiple_outputs.mdnew file mode 100644index 0000000000..cfa96fd0ac--- /dev/null+++ b/docs/examples/outputs/multiple_outputs.md@@ -0,0 +1,9 @@+# Showing multiple outputs++See the [API reference on outputs](../../api/outputs.md) for more info.++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/outputs/showing_multiple_outputs.py+///diff --git a/docs/examples/outputs/plots.md b/docs/examples/outputs/plots.mdnew file mode 100644index 0000000000..0ed95308a1--- /dev/null+++ b/docs/examples/outputs/plots.md@@ -0,0 +1,9 @@+# Showing plots++See the [plotting guide](../../guides/working_with_data/plotting.md) for an in-depth overview.++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/outputs/plots.py+///diff --git a/docs/examples/outputs/progress_bar.md b/docs/examples/outputs/progress_bar.mdnew file mode 100644index 0000000000..1ddbcb28dc--- /dev/null+++ b/docs/examples/outputs/progress_bar.md@@ -0,0 +1,7 @@+# Progress bar++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/outputs/progress_bar.py+///diff --git a/docs/examples/outputs/spinner.md b/docs/examples/outputs/spinner.mdnew file mode 100644index 0000000000..35df8d4081--- /dev/null+++ b/docs/examples/outputs/spinner.md@@ -0,0 +1,7 @@+# Spinner++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/outputs/spinner.py+///diff --git a/docs/examples/outputs/stacks.md b/docs/examples/outputs/stacks.mdnew file mode 100644index 0000000000..f239e8e761--- /dev/null+++ b/docs/examples/outputs/stacks.md@@ -0,0 +1,7 @@+# Horizontal and vertical stacking++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/outputs/stacks.py+///diff --git a/docs/examples/running_cells/async_await.md b/docs/examples/running_cells/async_await.mdnew file mode 100644index 0000000000..ed5793497e--- /dev/null+++ b/docs/examples/running_cells/async_await.md@@ -0,0 +1,9 @@+# Run on button click++marimo lets you use `await` to execute `async` functions.++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/running_cells/async_await.py+///diff --git a/docs/examples/running_cells/basics.md b/docs/examples/running_cells/basics.mdnew file mode 100644index 0000000000..e890ef4331--- /dev/null+++ b/docs/examples/running_cells/basics.md@@ -0,0 +1,8 @@+# Basic execution++/// marimo-embed-file+ size: xlarge+ mode: edit+ show-chrome: true+ filepath: examples/running_cells/basics.py+///diff --git a/docs/examples/running_cells/debugging.md b/docs/examples/running_cells/debugging.mdnew file mode 100644index 0000000000..be76ab67b3--- /dev/null+++ b/docs/examples/running_cells/debugging.md@@ -0,0 +1,9 @@+# Debugging++marimo lets you use PDB to debug cells. Insert a breakpoint by typing `breakpoint()`:++```python+x = 0+breakpoint()+1 / x+```diff --git a/docs/examples/running_cells/memory_cache.md b/docs/examples/running_cells/memory_cache.mdnew file mode 100644index 0000000000..8f1c5dc6ff--- /dev/null+++ b/docs/examples/running_cells/memory_cache.md@@ -0,0 +1,10 @@+# In-memory caching++Use [`mo.cache`][marimo.cache] to cache the output of expensive functions in+memory.++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/running_cells/in_memory_cache.py+///diff --git a/docs/examples/running_cells/multiple_definitions.md b/docs/examples/running_cells/multiple_definitions.mdnew file mode 100644index 0000000000..e46006fc39--- /dev/null+++ b/docs/examples/running_cells/multiple_definitions.md@@ -0,0 +1,18 @@+# Getting around multiple definition errors++marimo does not allow the same variable to be defined in multiple cells. This+restriction guarantees that the code on the page matches the outputs you see,+eliminates hidden state and hidden bugs, and lets marimo run your notebooks as+web apps and scripts, but it also has a learning curve. Here are some tips to+help you adapt.++!!! Tip "**Learn more**"++ Check out our guide on [multiple definition errors](../../guides/understanding_errors/multiple_definitions.md)+ to learn more, or watch our [YouTube video](https://www.youtube.com/watch?v=5TzAADGRfxU).++/// marimo-embed-file+ size: xxlarge+ mode: edit+ filepath: examples/running_cells/multiple_definitions.py+///diff --git a/docs/examples/running_cells/persistent_cache.md b/docs/examples/running_cells/persistent_cache.mdnew file mode 100644index 0000000000..ecb933ded1--- /dev/null+++ b/docs/examples/running_cells/persistent_cache.md@@ -0,0 +1,10 @@+# Persistent caching++Use [`mo.persistent_cache`][marimo.persistent_cache] to cache the output of+expensive computations to persistent storage (like disk).++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/running_cells/persistent_cache.py+///diff --git a/docs/examples/running_cells/refresh.md b/docs/examples/running_cells/refresh.mdnew file mode 100644index 0000000000..fe93415317--- /dev/null+++ b/docs/examples/running_cells/refresh.md@@ -0,0 +1,9 @@+# Refresh cells on a timer++Use [`mo.ui.refresh`][marimo.ui.refresh] to run a cell on a timer++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/ui/refresh.py+///diff --git a/docs/examples/running_cells/run_button.md b/docs/examples/running_cells/run_button.mdnew file mode 100644index 0000000000..73a0239e30--- /dev/null+++ b/docs/examples/running_cells/run_button.md@@ -0,0 +1,9 @@+# Run on button click++Use [mo.ui.run_button][marimo.ui.run_button] to trigger cell execution on button click.++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/ui/run_button.py+///diff --git a/docs/examples/running_cells/stop.md b/docs/examples/running_cells/stop.mdnew file mode 100644index 0000000000..dabfbd8842--- /dev/null+++ b/docs/examples/running_cells/stop.md@@ -0,0 +1,9 @@+# Stopping execution++Use [`mo.stop`][marimo.stop] to conditionally stop execution of a cell.++/// marimo-embed-file+ size: xlarge+ mode: edit+ filepath: examples/control_flow/stop_execution.py+///diff --git a/docs/guides/working_with_data/sql.md b/docs/guides/working_with_data/sql.mdindex 1a097ed750..bed1c670aa 100644--- a/docs/guides/working_with_data/sql.md+++ b/docs/guides/working_with_data/sql.md@@ -185,6 +185,8 @@ postgres_engine = sqlmodel.create_engine("postgresql://username:password@server:duckdb_conn = duckdb.connect("file.db")```+### Querying a custom database+marimo will auto-discover the engine and let you select it in the SQL cell's connection dropdown.<div align="center">diff --git a/docs/stylesheets/extra.css b/docs/stylesheets/extra.cssindex c737658d23..d8b1e70ba4 100644--- a/docs/stylesheets/extra.css+++ b/docs/stylesheets/extra.css@@ -87,3 +87,7 @@ video {border: 1px solid #ebebeb;border-radius: 5px;}++.examples-grid img {+ max-height: 125px;+}diff --git a/examples/outputs/accordion.py b/examples/outputs/accordion.pynew file mode 100644index 0000000000..b6e37a6e9b--- /dev/null+++ b/examples/outputs/accordion.py@@ -0,0 +1,28 @@+import marimo++__generated_with = "0.12.9"+app = marimo.App()+++def _():+ import marimo as mo+ return (mo,)+++def _(mo):+ mo.accordion(+ {+ "Door 1": mo.md("Nothing!"),+ "Door 2": mo.md("Nothing!"),+ "Door 3": mo.md(+ ""+ ),+ }+ )+ return+++if __name__ == "__main__":+ app.run()diff --git a/examples/outputs/audio.py b/examples/outputs/audio.pynew file mode 100644index 0000000000..3af9c6c48f--- /dev/null+++ b/examples/outputs/audio.py@@ -0,0 +1,6 @@+# /// script+# requires-python = ">=3.12"+# dependencies = [+# "marimo",+# ]+# ///diff --git a/examples/outputs/basic_markdown.py b/examples/outputs/basic_markdown.pynew file mode 100644index 0000000000..76cbe8050d--- /dev/null+++ b/examples/outputs/basic_markdown.py@@ -0,0 +1,29 @@+import marimo++__generated_with = "0.12.9"+app = marimo.App()+++def _():+ import marimo as mo+ return (mo,)++[email protected](hide_code=True)+def _(mo):+ mo.md(+ """+ Create a "Markdown" cell by clicking the `Markdown` button below,+ or through the cell action menu.++ Markdown is represented as Python under-the-hood, using the `mo.md()`+ function — so you'll need to import marimo as mo into your notebook+ first!+ """+ )+ return+++if __name__ == "__main__":+ app.run()diff --git a/examples/outputs/capture_console_outputs.py b/examples/outputs/capture_console_outputs.pynew file mode 100644index 0000000000..d0ba3b9abc--- /dev/null+++ b/examples/outputs/capture_console_outputs.py@@ -0,0 +1,23 @@+import marimo++__generated_with = "0.12.9"+app = marimo.App()+++def _():+ import marimo as mo+ return (mo,)+++def _(mo):+ with mo.capture_stdout() as output:+ print("Hello, world")++ mo.md(output.getvalue())+ return (output,)+++if __name__ == "__main__":+ app.run()diff --git a/examples/outputs/cell_output.py b/examples/outputs/cell_output.pynew file mode 100644index 0000000000..df2db094f2--- /dev/null+++ b/examples/outputs/cell_output.py@@ -0,0 +1,37 @@+import marimo++__generated_with = "0.12.8"+app = marimo.App()+++def _(mo):+ mo.md(+ """+ The last expression of a cell is its visual output. This output+ appears above the cell when editing a notebook, with notebook code+ serving as a "caption" for the output. Outputs can be configured+ to appear below cells in the user settings.++ If running+ a notebook as an app, the output is the visual representation+ of the cell (code is hidden by default).+ """+ )+ return+++def _():+ "Hello, world!"+ return+++def _():+ import marimo as mo+ return (mo,)+++if __name__ == "__main__":+ app.run()diff --git a/examples/outputs/conditional_output.py b/examples/outputs/conditional_output.pynew file mode 100644index 0000000000..4458b70fcd--- /dev/null+++ b/examples/outputs/conditional_output.py@@ -0,0 +1,74 @@+import marimo++__generated_with = "0.12.9"+app = marimo.App()+++def _():+ import marimo as mo+ return (mo,)+++def _(mo):+ checkbox = mo.ui.checkbox()+ checkbox+ return (checkbox,)++[email protected](hide_code=True)+def _(mo):+ mo.md("""Use inline if expressions to conditionally show a value""")+ return+++def _(checkbox):+ "Checkbox is checked" if checkbox.value else "Checkbox is not checked"+ return++[email protected](hide_code=True)+def _(mo):+ mo.md(+ """+ The next cell does **not** show anything, since an if statement does not+ have a value:+ """+ )+ return+++def _(checkbox, mo):+ if checkbox.value:+ mo.md("Checkbox is checked")+ else:+ mo.md("Checkbox is not checked")+ return++[email protected](hide_code=True)+def _(mo):+ mo.md("""A value of `None` produces the empty output:""")+ return+++def _(checkbox):+ checkbox+ return+++def _(checkbox, mo):+ _output = None+ if checkbox.value:+ _output = mo.md("Checkbox is checked.")+ _output+ return+++if __name__ == "__main__":+ app.run()diff --git a/examples/outputs/console_outputs.py b/examples/outputs/console_outputs.pynew file mode 100644index 0000000000..f0d46b7cf9--- /dev/null+++ b/examples/outputs/console_outputs.py@@ -0,0 +1,26 @@+import marimo++__generated_with = "0.12.9"+app = marimo.App()+++def _():+ import marimo as mo+ return (mo,)+++def _(mo):+ print("This is a console output")+ print("Notice that it's below the cell.")+ print("You can configure where outputs show up in your user configuration.")++ mo.md(+ "This is a cell output. Console outputs show up below a cell; cell outputs show up above."+ )+ return+++if __name__ == "__main__":+ app.run()diff --git a/examples/outputs/dataframes.py b/examples/outputs/dataframes.pynew file mode 100644index 0000000000..2064c67e0e--- /dev/null+++ b/examples/outputs/dataframes.py@@ -0,0 +1,56 @@+# /// script+# requires-python = ">=3.12"+# dependencies = [+# "marimo",+# "vega-datasets==0.9.0",+# ]+# ///++import marimo++__generated_with = "0.12.9"+app = marimo.App()+++def _():+ import marimo as mo+ return (mo,)+++def _():+ from vega_datasets import data+ return (data,)+++def _(data):+ df = data.cars()+ return (df,)++[email protected](hide_code=True)+def _(mo):+ mo.md(+ """+ marimo has a rich dataframe viewer built-in:++ - built-in global search+ - per-column sorting and filtering+ - per-column histograms+ - download filtered views+ - paginate through the whole dataframe+ """+ )+ return+++def _(df):+ df+ return+++if __name__ == "__main__":+ app.run()diff --git a/examples/outputs/plots.py b/examples/outputs/plots.pynew file mode 100644index 0000000000..13eebdc71c--- /dev/null+++ b/examples/outputs/plots.py@@ -0,0 +1,63 @@+# /// script+# requires-python = ">=3.12"+# dependencies = [+# "marimo",+# "matplotlib==3.10.1",+# "numpy==2.2.4",+# ]+# ///++import marimo++__generated_with = "0.12.9"+app = marimo.App()+++def _():+ import marimo as mo+ return (mo,)+++def _():+ import matplotlib.pyplot as plt+ return (plt,)++[email protected](hide_code=True)+def _(mo):+ mo.md("""Output a plot object, such as an axis or figure, to see the plot.""")+ return+++def _(plt):+ import numpy as np++ x = np.linspace(0, 10)+ plt.plot(x, x**2)+ plt.gca()+ return np, x++[email protected](hide_code=True)+def _(mo):+ mo.md(+ """+ Calling `show()` methods displays the plot in the console area, which can be+ helpful for debugging because console outputs do not show up in the "app" preview.+ """+ )+ return+++def _(plt, x):+ plt.plot(x, x**3)+ plt.show()+ return+++if __name__ == "__main__":+ app.run()diff --git a/examples/outputs/progress_bar.py b/examples/outputs/progress_bar.pynew file mode 100644index 0000000000..5c0f912dbd--- /dev/null+++ b/examples/outputs/progress_bar.py@@ -0,0 +1,34 @@+import marimo+++app = marimo.App()++def _():+ import marimo as mo+ return (mo,)++def _(mo,):+ rerun = mo.ui.button(label="Rerun")+ rerun+ return (rerun,)++async def _(mo, rerun):+ 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+++if __name__ == "__main__":+ app.run()+diff --git a/examples/outputs/showing_multiple_outputs.py b/examples/outputs/showing_multiple_outputs.pynew file mode 100644index 0000000000..232063057e--- /dev/null+++ b/examples/outputs/showing_multiple_outputs.py@@ -0,0 +1,23 @@+import marimo++__generated_with = "0.12.9"+app = marimo.App()+++def _():+ import marimo as mo+ return (mo,)+++def _(mo):+ for i in range(3):+ mo.output.append(mo.md(f"$i = {i}$"))++ mo.output.append(mo.md("Completed iteration."))+ return (i,)+++if __name__ == "__main__":+ app.run()diff --git a/examples/outputs/spinner.py b/examples/outputs/spinner.pynew file mode 100644index 0000000000..25fa203107--- /dev/null+++ b/examples/outputs/spinner.py@@ -0,0 +1,34 @@+import marimo++__generated_with = "0.12.9"+app = marimo.App()+++def _():+ import marimo as mo+ return (mo,)+++def _(mo):+ rerun = mo.ui.button(label="Rerun")+ rerun+ return (rerun,)+++async def _(mo, rerun):+ 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 (asyncio,)+++if __name__ == "__main__":+ app.run()diff --git a/examples/outputs/stacks.py b/examples/outputs/stacks.pynew file mode 100644index 0000000000..a5face4e68--- /dev/null+++ b/examples/outputs/stacks.py@@ -0,0 +1,33 @@+import marimo++__generated_with = "0.12.9"+app = marimo.App()+++def _():+ import marimo as mo+ return (mo,)+++def _(mo):+ t = mo.ui.date()+ n = mo.ui.slider(1, 10)+ return n, t+++def _(mo, n, t):+ mo.hstack([t, n], justify="start")+ return+++def _(mo, n, t):+ mo.vstack([t, n])+ return+++if __name__ == "__main__":+ app.run()diff --git a/examples/running_cells/async_await.py b/examples/running_cells/async_await.pynew file mode 100644index 0000000000..a316730dc7--- /dev/null+++ b/examples/running_cells/async_await.py@@ -0,0 +1,30 @@+import marimo++__generated_with = "0.12.9"+app = marimo.App()+++def _():+ import marimo as mo+ return (mo,)+++def wait_for():+ async def wait_for(seconds):+ import asyncio+ print(f"Waiting for {seconds} seconds ...")+ await asyncio.sleep(seconds)+ print("Done!")+ return (wait_for,)+++async def _(wait_for):+ await wait_for(1)+ return+++if __name__ == "__main__":+ app.run()diff --git a/examples/running_cells/basics.py b/examples/running_cells/basics.pynew file mode 100644index 0000000000..5ed9118924--- /dev/null+++ b/examples/running_cells/basics.py@@ -0,0 +1,48 @@+import marimo++__generated_with = "0.12.9"+app = marimo.App()+++def _():+ import marimo as mo+ return (mo,)++[email protected](hide_code=True)+def _(mo):+ mo.md(+ """+ marimo knows how your cells are related, and can automatically update+ outputs like a spreadsheet. This eliminates hidden state and hidden bugs, accelerates data exploration,+ and makes it possible for marimo to run your notebooks as scripts and web apps.+ For expensive notebooks, you can [turn this+ behavior off](https://docs.marimo.io/guides/expensive_notebooks/) via the notebook footer.++ Try updating the values of variables below and see what happens! You can also try deleting a cell.+ """+ )+ return+++def _():+ x = 0+ return (x,)+++def _():+ y = 1+ return (y,)+++def _(x):+ x+ return+++if __name__ == "__main__":+ app.run()diff --git a/examples/running_cells/debugging.py b/examples/running_cells/debugging.pynew file mode 100644index 0000000000..e83fb354a0--- /dev/null+++ b/examples/running_cells/debugging.py@@ -0,0 +1,22 @@+import marimo++__generated_with = "0.12.9"+app = marimo.App()+++def foo():+ def foo(x):+ breakpoint()+ return 1 / x+ return (foo,)+++def _(foo):+ foo(1)+ return+++if __name__ == "__main__":+ app.run()diff --git a/examples/running_cells/in_memory_cache.py b/examples/running_cells/in_memory_cache.pynew file mode 100644index 0000000000..60addb7705--- /dev/null+++ b/examples/running_cells/in_memory_cache.py@@ -0,0 +1,47 @@+import marimo++__generated_with = "0.12.9"+app = marimo.App(app_title="In Memory Cache")+++def _():+ import marimo as mo+ return (mo,)+++def _(mo):+ @mo.cache+ def sleep_for(t: int):+ import time++ print("Sleeping")+ time.sleep(t)+ return t+ return (sleep_for,)++[email protected](hide_code=True)+def _(mo):+ mo.md(+ """+ Use `mo.cache` to cache the outputs of expensive functions. The first+ time the function is called with unseen arguments, it will execute and+ return the computed value. Subsequent calls with the same arguments will+ return cached results.++ Experiment with the invocation below to get a feel for how this works.+ """+ )+ return+++def _(sleep_for):+ sleep_for(1)+ return+++if __name__ == "__main__":+ app.run()\ No newline at end of filediff --git a/examples/running_cells/multiple_definitions.py b/examples/running_cells/multiple_definitions.pynew file mode 100644index 0000000000..876ad5b009--- /dev/null+++ b/examples/running_cells/multiple_definitions.py@@ -0,0 +1,83 @@+# /// script+# requires-python = ">=3.12"+# dependencies = [+# "marimo",+# "matplotlib==3.10.1",+# ]+# ///+import marimo++__generated_with = "0.12.9"+app = marimo.App()+++def _():+ import marimo as mo+ return (mo,)++[email protected](hide_code=True)+def _(mo):+ mo.md(+ r"""+ ## Use local variables++ Variables prefixed with an underscore are local to a cell, and can be redefined.+ """+ )+ return+++def _():+ for _i in range(3):+ print(_i)+ return+++def _():+ for _i in range(4, 6):+ print(_i)+ return+++def _():+ # _i is not defined in this cell+ _i+ return++[email protected](hide_code=True)+def _(mo):+ mo.md(+ r"""+ ## Wrap code in functions++ Wrap cells in functions to minimize the number of temporary globals you introduce.+ """+ )+ return+++def _():+ import matplotlib.pyplot as plt+ return (plt,)+++def _(plt):+ def _():+ fig, ax = plt.subplots()+ plt.plot([1, 2])+ return ax++ _()+ return+++if __name__ == "__main__":+ app.run()diff --git a/examples/running_cells/persistent_cache.py b/examples/running_cells/persistent_cache.pynew file mode 100644index 0000000000..e171ed8a30--- /dev/null+++ b/examples/running_cells/persistent_cache.py@@ -0,0 +1,47 @@+import marimo++__generated_with = "0.12.9"+app = marimo.App(app_title="In Memory Cache")+++def _():+ import marimo as mo+ return (mo,)+++def _(mo):+ @mo.persistent_cache+ def sleep_for(t: int):+ import time++ print("Sleeping")+ time.sleep(t)+ return t+ return (sleep_for,)++[email protected](hide_code=True)+def _(mo):+ mo.md(+ """+ Use `mo.persistent_cache` to cache the outputs of expensive computations to persistent storage. The first+ time the function is called with unseen arguments, it will execute and+ return the computed value. Subsequent calls with the same arguments will+ return cached results.++ Experiment with the invocation below to get a feel for how this works.+ """+ )+ return+++def _(sleep_for):+ sleep_for(1)+ return+++if __name__ == "__main__":+ app.run()diff --git a/examples/ui/data_editor.py b/examples/ui/data_editor.pynew file mode 100644index 0000000000..c985b7a81b--- /dev/null+++ b/examples/ui/data_editor.py@@ -0,0 +1,61 @@+import marimo++__generated_with = "0.12.9"+app = marimo.App(width="medium")+++def _():+ import marimo as mo+ return (mo,)+++def _():+ import os+ return (os,)+++def _():+ DATA_FILE = "data.csv"+ return (DATA_FILE,)+++def _(DATA_FILE, os):+ if not os.path.exists(DATA_FILE):+ from vega_datasets import data++ data.cars().to_csv(DATA_FILE)+++ import polars as pl++ df = pl.read_csv(DATA_FILE)+ return data, df, pl+++def _(df, mo):+ editor = mo.ui.data_editor(df).form(bordered=False)+ editor+ return (editor,)+++def _(mo):+ mo.md(+ "The following cell writes the updated dataframe to disk when the submit button is clicked."+ )+ return+++def _(DATA_FILE, editor):+ editor.value.write_csv(DATA_FILE)+ return+++if __name__ == "__main__":+ app.run()diff --git a/mkdocs.yml b/mkdocs.ymlindex 70279a3e76..a57fa8f96b 100644--- a/mkdocs.yml+++ b/mkdocs.yml@@ -161,6 +161,9 @@ nav:- Best practices: guides/best_practices.md- Troubleshooting: guides/troubleshooting.md- Dangerously set state: guides/state.md+ - Examples:+ - Examples: examples/index.md+ - Recipes: recipes.md- API Reference:- API Reference: api/index.md- Markdown: api/markdown.md@@ -231,10 +234,6 @@ nav:- Cell: api/cell.md- Miscellaneous: api/miscellaneous.md- Commands: cli.md- - Examples:- - Notebooks: examples.md- - Recipes: recipes.md- - Islands: guides/island_example.md- FAQ: faq.md- Community:- Community: community.md