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
feat: preview marimo-islands, add docs (#1335)
Myles Scolnick0739042e516b
diff --git a/docs/_static/css/custom.css b/docs/_static/css/custom.cssindex 8a40b366c7..c5f108349a 100644--- a/docs/_static/css/custom.css+++ b/docs/_static/css/custom.css@@ -178,3 +178,8 @@ details.sd-dropdown .sd-summary-up {padding-top: 1rem;padding-bottom: 1rem;}++/* Hide Furo warning about unrelated duplicate table of contents error */+.marimo .contents::before {+ display: none !important;+}diff --git a/docs/guides/exporting.md b/docs/guides/exporting.mdindex 364e91ae42..0a7fc8e6ea 100644--- a/docs/guides/exporting.md+++ b/docs/guides/exporting.md@@ -39,3 +39,20 @@ marimo export script notebook.py -o notebook.script.pyExporting to a flat Python script does not support top-level await.If you have top-level await in your notebook, you can still execute the notebook as a script with `python notebook.py`.```++## Export to markdown++Export the notebook to markdown at the command-line.+This exports the notebook in top to bottom order, so the cells are in the order as they appear in the notebook.++```bash+marimo export md notebook.py -o notebook.md+```++This can be useful to plug into other tools that read markdown, such as [Quarto](https://quarto.org/) or [MyST](https://myst-parser.readthedocs.io/).++You can also convert the markdown back to a marimo notebook:++```bash+marimo convert notebook.md > notebook.py+```diff --git a/docs/guides/island_example.md b/docs/guides/island_example.mdnew file mode 100644index 0000000000..6f89ee99f7--- /dev/null+++ b/docs/guides/island_example.md@@ -0,0 +1,118 @@+# marimo islands 🏝️++<!-- marimo js/ccs -->+<script+ type="module"+ src="https://cdn.jsdelivr.net/npm/@marimo-team/[email protected]/dist/main.js"+></script>+<link+ href="https://cdn.jsdelivr.net/npm/@marimo-team/[email protected]/dist/style.css"+ rel="stylesheet"+ crossorigin="anonymous"+/>+<!-- fonts -->+<link rel="preconnect" href="https://fonts.googleapis.com" />+<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />+<link+ href="https://fonts.googleapis.com/css2?family=Fira+Mono:wght@400;500;700&family=Lora&family=PT+Sans:wght@400;700&display=swap"+ rel="stylesheet"+/>+<link+ rel="stylesheet"+ href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css"+ integrity="sha384-wcIxkf4k558AjM3Yz3BBFQUbk/zgIYC2R0QpeeYb+TwlBVMrlgLqwRjRtGZiK7ww"+ crossorigin="anonymous"+/>++```{admonition} Preview+:class: note++Islands are an early feature. While the API likely won't change, there are some improvements we'd like to make before we consider them stable.+Please let us know on [GitHub](https://github.com/marimo-team/marimo/issues) if you run into any issues or have any feedback!+```++> This content below is powered by marimo's reactive runtime. It will become interactive after initializing the marimo runtime.++<hr/>++<marimo-island data-app-id="main" data-cell-id="Hbol" data-reactive="true">+ <marimo-cell-output></marimo-cell-output>+ <marimo-cell-code hidden>import%20marimo%20as%20mo</marimo-cell-code>+</marimo-island>+<marimo-island data-app-id="main" data-cell-id="MJUe" data-reactive="true">+ <marimo-cell-output>+ <marimo-ui-element object-id="MJUe-0" random-id="0a0beb44-f946-450d-a690-678a45aeb110">+ <marimo-slider+ data-initial-value="2"+ data-label="null"+ data-start="0"+ data-stop="10"+ data-steps="[]"+ data-debounce="false"+ data-orientation='"horizontal"'+ data-show-value="false"+ data-full-width="false"+ ></marimo-slider>+ </marimo-ui-element>+ </marimo-cell-output>+ <marimo-cell-code hidden>slider%20%3D%20mo.ui.slider(0%2C%2010,value=2)%3B%20slider</marimo-cell-code>+</marimo-island>+<marimo-island data-app-id="main" data-cell-id="vblA" data-reactive="true">+ <marimo-cell-output>+ <span class="markdown"><span class="paragraph">Hello, islands! 🏝️🏝️</span></span>+ </marimo-cell-output>+ <marimo-ui-element object-id="9c045fc3-f483-4024-ad01-cbf8f06cd7b7" random-id="9c045fc3-f483-4024-ad01-cbf8f06cd7b7">+ <marimo-code-editor+ data-initial-value='"mo.md(f'Hello, islands! {\"\ud83c\udfdd\ufe0f\" * slider.value}')"'+ data-label="null"+ data-language='"python"'+ data-placeholder='""'+ data-disabled="false"+ ></marimo-code-editor>+ </marimo-ui-element>+</marimo-island>++<hr style="margin: 20px 0;" />++````{dropdown} See the HTML++```html+<marimo-island data-app-id="main" data-cell-id="Hbol" data-reactive="true">+ <marimo-cell-output></marimo-cell-output>+ <marimo-cell-code hidden>import%20marimo%20as%20mo</marimo-cell-code>+</marimo-island>+<marimo-island data-app-id="main" data-cell-id="MJUe" data-reactive="true">+ <marimo-cell-output>+ <marimo-ui-element object-id="MJUe-0" random-id="0a0beb44-f946-450d-a690-678a45aeb110">+ <marimo-slider+ data-initial-value="2"+ data-label="null"+ data-start="0"+ data-stop="10"+ data-steps="[]"+ data-debounce="false"+ data-orientation='"horizontal"'+ data-show-value="false"+ data-full-width="false"+ ></marimo-slider>+ </marimo-ui-element>+ </marimo-cell-output>+ <marimo-cell-code hidden>slider%20%3D%20mo.ui.slider(0%2C%2010,value=2)%3B%20slider</marimo-cell-code>+</marimo-island>+<marimo-island data-app-id="main" data-cell-id="vblA" data-reactive="true">+ <marimo-cell-output>+ <span class="markdown"><span class="paragraph">Hello, islands! 🏝️🏝️</span></span>+ </marimo-cell-output>+ <marimo-ui-element object-id="9c045fc3-f483-4024-ad01-cbf8f06cd7b7" random-id="9c045fc3-f483-4024-ad01-cbf8f06cd7b7">+ <marimo-code-editor+ data-initial-value='"mo.md(f'Hello, islands! {\"\ud83c\udfdd\ufe0f\" * slider.value}')"'+ data-label="null"+ data-language='"python"'+ data-placeholder='""'+ data-disabled="false"+ ></marimo-code-editor>+ </marimo-ui-element>+</marimo-island>+```++````diff --git a/docs/guides/wasm.md b/docs/guides/wasm.mdindex 65ff4f4ba8..8170db4f40 100644--- a/docs/guides/wasm.md+++ b/docs/guides/wasm.md@@ -204,6 +204,79 @@ You can optionally render embedded notebooks in read-only mode by appending<iframe src="https://marimo.app/l/c7h6pz?mode=read&embed=true" width="100%" height="600" class="demo" frameBorder="0"></iframe>+## 🏝️ Islands++```{admonition} Preview+:class: note++Islands are an early feature. While the API likely won't change, there are some improvements we'd like to make before we consider them stable.+Please let us know on [GitHub](https://github.com/marimo-team/marimo/issues) if you run into any issues or have any feedback!+```++marimo islands are a way to embed marimo outputs and/or python code in your HTML that will become interactive when the page is loaded. This is useful for creating interactive blog posts, tutorials, and educational materials, all powered by marimo's reactive runtime.++Check out an [example island-powered document](./island_example.md).++### Islands in action++```{admonition} Advanced topic!+:class: warning++Islands are an advanced concept that is meant to be a building block for creating integrations with existing tools such as static site generators or documentation tools.+```++In order to use marimo islands, you need to import the necessary JS/CSS headers in your HTML file, and use our custom HTML tags to define the islands.++```html+<head>+ <!-- marimo js/ccs -->+ <script+ type="module"+ src="https://cdn.jsdelivr.net/npm/@marimo-team/islands@<version>/dist/main.js"+ ></script>+ <link+ href="https://cdn.jsdelivr.net/npm/@marimo-team/islands@<version>/dist/style.css"+ rel="stylesheet"+ crossorigin="anonymous"+ />+ <!-- fonts -->+ <link rel="preconnect" href="https://fonts.googleapis.com" />+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />+ <link+ href="https://fonts.googleapis.com/css2?family=Fira+Mono:wght@400;500;700&family=Lora&family=PT+Sans:wght@400;700&display=swap"+ rel="stylesheet"+ />+ <link+ rel="stylesheet"+ href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css"+ integrity="sha384-wcIxkf4k558AjM3Yz3BBFQUbk/zgIYC2R0QpeeYb+TwlBVMrlgLqwRjRtGZiK7ww"+ crossorigin="anonymous"+ />+</head>++<body>+ <marimo-island data-app-id="main" data-cell-id="MJUe" data-reactive="true">+ <marimo-cell-output>+ <span class="markdown">+ <span class="paragraph">Hello, islands!</span>+ </span>+ </marimo-cell-output>+ <marimo-cell-code hidden>mo.md('Hello islands 🏝️!')</marimo-cell-code>+ </marimo-island>+</body>+```++### Generating islands++While you can generate the HTML code for islands yourself, it it recommend to use our `MarimoIslandGenerator` class to generate the HTML code for you.++```{eval-rst}+.. autoclass:: marimo.MarimoIslandGenerator+ :members:++ .. autoclasstoc::+```+## LimitationsWhile WASM notebooks let you get up and running with marimo instantly, theydiff --git a/marimo/__init__.py b/marimo/__init__.pyindex 4ed7411631..4674ad4ab7 100644--- a/marimo/__init__.py+++ b/marimo/__init__.py@@ -17,7 +17,7 @@ __all__ = ["Cell","MarimoStopError","create_asgi_app",- "experimental_MarimoIslandGenerator",+ "MarimoIslandGenerator","accordion","carousel","as_html",@@ -63,9 +63,7 @@ __version__ = "0.5.0"from marimo._ast.app import Appfrom marimo._ast.cell import Cell-from marimo._islands.island_generator import (- MarimoIslandGenerator as experimental_MarimoIslandGenerator,-)+from marimo._islands.island_generator import MarimoIslandGeneratorfrom marimo._output.doc import docfrom marimo._output.formatting import as_htmlfrom marimo._output.hypertext import Htmldiff --git a/pyproject.toml b/pyproject.tomlindex 5720f424da..b8ded13768 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -283,6 +283,7 @@ omit = ["marimo/_tutorials/*"][tool.typos.default.extend-words]wheres = "wheres"+Ue = "Ue" # Used in one of the cell IDs[tool.typos.files]extend-exclude = [