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.

Fixes to layout examples (#2418)

Akshay Agrawala9e4f89ff623
diff --git a/examples/README.md b/examples/README.md
index 396d44b748..6278c2594d 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -3,7 +3,8 @@
This folder contains example marimo notebooks.
- 🖱️ [`ui/`](ui/): marimo's many UI elements or widgets
-- 🛢️ [`sql/`](sql/): SQL and Python inter-op
+- 🛢️ [`sql/`](sql/): using marimo's SQL cells
+- 📽️ [`layouts/`](layouts/): 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
diff --git a/examples/layouts/README.md b/examples/layouts/README.md
new file mode 100644
index 0000000000..df0e817b3f
--- /dev/null
+++ b/examples/layouts/README.md
@@ -0,0 +1,26 @@
+# Layouts 📽️
+
+These examples show how to use marimo's built-in features for laying out
+notebooks in interesting ways, such as presenting notebooks as slides and
+adding sidebars.
+
+> [!TIP]
+> Submit a
+> [pull request](https://github.com/marimo-team/marimo/pulls) to add an example!
+
+
+## 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/layouts/sidebar.py b/examples/layouts/sidebar.py
index da8c2c914f..ffad9edb72 100644
--- a/examples/layouts/sidebar.py
+++ b/examples/layouts/sidebar.py
@@ -6,15 +6,26 @@
# "vega-datasets==0.9.0",
# ]
# ///
+
import marimo
__generated_with = "0.8.20"
app = marimo.App(width="full")
[email protected](hide_code=True)
+def __(mo):
+ mo.md(
+ r"""
+ !!! tip "This notebook is best viewed as an app."
+ Hit `Cmd/Ctrl+.` or click the "app view" button in the bottom right.
+ """
+ )
+ return
+
+
@app.cell
def __():
- # Imports
import marimo as mo
import altair as alt
from vega_datasets import data
@@ -23,7 +34,6 @@ def __():
@app.cell
def __(data):
- # Data
gapminder = data.gapminder()
return (gapminder,)
@@ -105,7 +115,7 @@ def __(mo, population, year):
mo.md(
f"""
[{mo.icon("lucide:twitter")} Twitter](https://twitter.com/marimo_io)
-
+
[{mo.icon("lucide:github")} GitHub](https://github.com/marimo-team/marimo)
"""
)
diff --git a/examples/layouts/slides.py b/examples/layouts/slides.py
index 21b51abc7d..d77b37ddec 100644
--- a/examples/layouts/slides.py
+++ b/examples/layouts/slides.py
@@ -3,21 +3,35 @@
# dependencies = [
# "duckdb==1.1.1",
# "marimo",
+# "numpy==2.0.2",
+# "pandas==2.2.3",
# ]
# ///
+
import marimo
__generated_with = "0.8.20"
app = marimo.App(width="medium", layout_file="layouts/slides.slides.json")
[email protected](hide_code=True)
+def __(mo):
+ mo.md(
+ r"""
+ !!! tip "This notebook is best viewed as an app."
+ Hit `Cmd/Ctrl+.` or click the "app view" button in the bottom right.
+ """
+ )
+ return
+
+
@app.cell
def __(mo):
mo.md(
"""
# DuckDB Tricks 🦆
- ## We use a simple example data set to present a few tricks that are useful when using DuckDB.
+ We use a simple example data set to present a few tricks that are useful when using DuckDB.
>
> Turned into slides from <https://duckdb.org/2024/08/19/duckdb-tricks-part-1.html>
@@ -204,7 +218,6 @@ def __(mo):
def __(duckdb, mo):
# Utils
-
def print_and_run(sql: str):
result = duckdb.sql(sql)
sql = sql.strip()