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.

Update tutorials (#1407)

Akshay Agrawald1de084b8109
diff --git a/marimo/_tutorials/dataflow.py b/marimo/_tutorials/dataflow.py
index 02b3406204..3d7a8f7b78 100644
--- a/marimo/_tutorials/dataflow.py
+++ b/marimo/_tutorials/dataflow.py
@@ -1,7 +1,8 @@
# Copyright 2024 Marimo. All rights reserved.
+
import marimo
-__generated_with = "0.1.69"
+__generated_with = "0.6.0"
app = marimo.App()
@@ -17,7 +18,27 @@ def __(mo):
To provide reactive execution, marimo creates a dataflow graph out of your
cells.
- """
+ """
+ )
+ return
+
+
[email protected](hide_code=True)
+def __(mo):
+ mo.md(
+ rf"""
+ **Tip: disabling automatic execution.**
+
+ marimo lets you disable automatic execution: just go into the notebook settings
+ and set
+
+ "Runtime > On Cell Change" to "lazy".
+
+ When the runtime is lazy, after running a cell, marimo marks its
+ descendants as stale instead of automatically running them. The lazy
+ runtime puts you in control over when cells are run, while still giving
+ guarantees about the notebook state.
+ """
)
return
@@ -31,7 +52,7 @@ def __(mo):
A marimo notebook is a directed acyclic graph in which nodes represent
cells and edges represent data dependencies. marimo creates this graph by
analyzing each cell (without running it) to determine its
-
+
- references ("refs*), the global variables it reads but doesn't define;
- definitions ("defs"), the global variables it defines.
@@ -50,10 +71,10 @@ def __(mo):
mo.md(
"""
### Example
-
+
The next four cells plot a sine wave with a given period and amplitude.
- Each cell is labeled with its refs and defs.
- """
+ Each cell is labeled with its refs and defs.
+ """
)
return
@@ -98,7 +119,7 @@ def __(mo):
- `defs: {mo.defs()}`
"""
)
- return period,
+ return (period,)
@app.cell
@@ -111,7 +132,7 @@ def __(mo):
- `defs: {mo.defs()}`
"""
)
- return amplitude,
+ return (amplitude,)
@app.cell
@@ -143,7 +164,7 @@ def __(matplotlib_installed, mo, np, numpy_installed, plt):
- `defs: {mo.defs()}`
"""
)
- return plot_wave,
+ return (plot_wave,)
@app.cell(hide_code=True)
@@ -181,7 +202,7 @@ def __(mo):
+------------> | {} | <-------------+
+----+
```
-
+
The last cell, which doesn't define anything, produces the plot.
"""
)
@@ -238,14 +259,14 @@ def __(mo):
def __():
planet = "Mars"
planet
- return planet,
+ return (planet,)
@app.cell
def __():
planet = "Earth"
planet
- return planet,
+ return (planet,)
@app.cell(hide_code=True)
@@ -277,13 +298,13 @@ def __(mo):
@app.cell
def __():
count = 0
- return count,
+ return (count,)
@app.cell
def __():
count += 1
- return count,
+ return (count,)
@app.cell(hide_code=True)
@@ -350,7 +371,7 @@ def __(mo):
Delete this cell by clicking the trash bin icon.
"""
)
- return to_be_deleted,
+ return (to_be_deleted,)
@app.cell
@@ -374,13 +395,13 @@ def __(mo):
@app.cell
def __(two):
one = two - 1
- return one,
+ return (one,)
@app.cell
def __(one):
two = one + 1
- return two,
+ return (two,)
@app.cell(hide_code=True)
@@ -491,10 +512,11 @@ def __(mo, tips):
return
[email protected](hide_code=True)
def __(mo):
mo.md(
- """## What's next?
+ """
+ ## What's next?
Check out the tutorial on interactivity for a tour of UI elements:
@@ -622,13 +644,14 @@ def __():
"""
),
}
- return tips,
+ return (tips,)
@app.cell
def __():
import marimo as mo
- return mo,
+
+ return (mo,)
if __name__ == "__main__":
diff --git a/marimo/_tutorials/intro.py b/marimo/_tutorials/intro.py
index 237311afc9..cca55353f9 100644
--- a/marimo/_tutorials/intro.py
+++ b/marimo/_tutorials/intro.py
@@ -2,7 +2,7 @@
import marimo
-__generated_with = "0.3.12"
+__generated_with = "0.6.0"
app = marimo.App()
@@ -11,13 +11,13 @@ def __():
import marimo as mo
mo.md("# Welcome to marimo! 🌊🍃")
- return mo,
+ return (mo,)
@app.cell
def __(mo):
slider = mo.ui.slider(1, 22)
- return slider,
+ return (slider,)
@app.cell
@@ -36,6 +36,28 @@ def __(mo, slider):
return
[email protected](hide_code=True)
+def __(mo):
+ mo.accordion(
+ {
+ "Tip: disabling automatic execution": mo.md(
+ rf"""
+ marimo lets you disable automatic execution: just go into the
+ notebook settings and set
+
+ "Runtime > On Cell Change" to "lazy".
+
+ When the runtime is lazy, after running a cell, marimo marks its
+ descendants as stale instead of automatically running them. The
+ lazy runtime puts you in control over when cells are run, while
+ still giving guarantees about the notebook state.
+ """
+ )
+ }
+ )
+ return
+
+
@app.cell(hide_code=True)
def __(mo):
mo.md(
@@ -98,7 +120,7 @@ def __(changed, mo):
@app.cell
def __():
changed = False
- return changed,
+ return (changed,)
@app.cell(hide_code=True)
@@ -164,7 +186,8 @@ def __(mo):
@app.cell(hide_code=True)
def __(mo):
mo.md(
- """## 2. UI elements
+ """
+ ## 2. UI elements
Cells can output interactive UI elements. Interacting with a UI
element **automatically triggers notebook execution**: when
@@ -187,13 +210,13 @@ def __(mo):
@app.cell
def __(mo):
icon = mo.ui.dropdown(["🍃", "🌊", "✨"], value="🍃")
- return icon,
+ return (icon,)
@app.cell
def __(icon, mo):
repetitions = mo.ui.slider(1, 16, label=f"number of {icon.value}: ")
- return repetitions,
+ return (repetitions,)
@app.cell
@@ -251,7 +274,8 @@ def __(mo):
@app.cell(hide_code=True)
def __(mo):
mo.md(
- """## 5. The `marimo` command-line tool
+ """
+ ## 5. The `marimo` command-line tool
**Creating and editing notebooks.** Use
@@ -425,13 +449,13 @@ def __():
"""
),
"Configuration": (
- """
+ """
Configure the editor by clicking the gears icon near the top-right
of the screen.
"""
),
}
- return tips,
+ return (tips,)
if __name__ == "__main__":
diff --git a/marimo/_tutorials/markdown.py b/marimo/_tutorials/markdown.py
index 9c45e51c7c..e861a8ae3f 100644
--- a/marimo/_tutorials/markdown.py
+++ b/marimo/_tutorials/markdown.py
@@ -1,7 +1,8 @@
# Copyright 2024 Marimo. All rights reserved.
+
import marimo
-__generated_with = "0.1.69"
+__generated_with = "0.6.0"
app = marimo.App()
@@ -11,9 +12,7 @@ def __(mo):
"""
# Hello, Markdown!
- Use marimo's "`md`" function to embed rich text into your marimo
- apps. This function compiles Markdown into HTML that marimo
- can display.
+ Use marimo's "`md`" function to write markdown. This function compiles Markdown into HTML that marimo can display.
For example, here's the code that rendered the above title and
paragraph:
@@ -34,10 +33,25 @@ def __(mo):
return
+def __(mo):
+ mo.md(
+ rf"""
+ **Tip: toggling between Markdown and Python views**
+
+ Although markdown is written with `mo.md`, marimo provides a markdown view
+ that hides this boilerplate from you. You can toggle between Markdown and
+ Python views by clicking the button in the top-right of this cell or entering
+ `Ctrl/Cmd+Shift+M`.
+ """
+ )
+ return
+
+
@app.cell(hide_code=True)
def __(mo):
mo.md(
- r"""
+ r"""
## LaTeX
You can embed LaTeX in Markdown.
@@ -98,7 +112,7 @@ def __(mo):
return
[email protected](hide_code=True)
def __(
matplotlib_installed,
missing_matplotlib_msg,
@@ -136,7 +150,7 @@ def __(
return
[email protected](hide_code=True)
def __(mo):
leaves = mo.ui.slider(1, 32, label="🍃: ")
@@ -285,12 +299,11 @@ def __(
def __(amplitude, mo, period):
mo.md(
f"""
+ **A sin curve.**
- **A sin curve.**
-
- - {amplitude}
- - {period}
- """
+ - {amplitude}
+ - {period}
+ """
)
return
@@ -299,7 +312,6 @@ def __(amplitude, mo, period):
def __(amplitude, mo, period, plotsin):
mo.md(
rf"""
-
You're viewing the graph of
\[