marimo snippets
Example usage of marimo snippets, with mkdocs.
marimo snippets lets you selectively render Python code snippets as notebooks, or add buttons to snippets that link out to notebooks.
These snippets run via WebAssembly, meaning the browser executes Python code (no backend required). Most packages are supported, including numpy, scipy, scikit-learn, matplotlib, plotly, altair, polars, duckdb, and more. Consult the pyodide documentation for a full list.
Initialize marimo snippets
Include the following to load marimo snippets on your web page:
Linking to notebooks
Use <marimo-button>
to link out to a notebook:
<div>
<marimo-button>
```python
def hello_world():
print("Hello, World!")
hello_world()
```
</marimo-button>
</div>
The result of this snippet is shown below.
Embedding notebooks inline
It's also possible to replace a code block with an inlined notebook,
using <marimo-iframe>
:
<div>
<marimo-iframe>
```python
def hello_world():
print("Hello, World!")
hello_world()
```
</marimo-iframe>
</div>
The result of this snippet is shown below.
Merging code blocks
Multiple code blocks can be merged together to form a single notebook:
<div>
<marimo-iframe data-height="600px">
```md
# Introduction
You can also add markdown cells to your notebooks.
```
```python
import marimo as mo
```
```python
slider = mo.ui.slider(1, 10)
slider
```
```python
slider.value * "🍃"
```
</marimo-iframe>
</div>
The result of this snippet is shown below.