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
fix: marimo islands (Windows-related) + doc touchups (#3242)
Srihari Thyagarajanf25bdf656a14
diff --git a/.gitignore b/.gitignoreindex 5a679caa94..28dea1c167 100644--- a/.gitignore+++ b/.gitignore@@ -89,6 +89,7 @@ venv/ENV/env.bak/venv.bak/+uv.lock# editors*.swpdiff --git a/docs/guides/exporting.md b/docs/guides/exporting.mdindex e4622e8e36..358733940e 100644--- a/docs/guides/exporting.md+++ b/docs/guides/exporting.md@@ -242,6 +242,75 @@ marimo islands are a way to embed marimo outputs and/or python code in your HTMLCheck out an [example island-powered document](./island_example.md).+### Generating islands++Use `MarimoIslandGenerator` to generate HTML for islands++!!! example+ /// tab | From code blocks++ ```python+ import asyncio+ import sys+ from marimo import MarimoIslandGenerator++ if sys.platform == 'win32':+ asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())++ async def main():+ generator = MarimoIslandGenerator()+ block1 = generator.add_code("import marimo as mo")+ block2 = generator.add_code("mo.md('Hello, islands!')")++ # Build the app+ app = await generator.build()++ # Render the app+ output = f"""+ <html>+ <head>+ {generator.render_head()}+ </head>+ <body>+ {block1.render(display_output=False)}+ {block2.render()}+ </body>+ </html>+ """+ print(output)+ # Save the HTML to a file+ output_file = "output.html"+ with open(output_file, "w", encoding="utf-8") as f:+ f.write(output)++ if __name__ == '__main__':+ asyncio.run(main())+ ```++ ///++ /// tab | From notebook files++ ```python+ from marimo import MarimoIslandGenerator++ # Create the generator from file+ generator = MarimoIslandGenerator.from_file("./<notebook-name>.py", display_code=False)++ # Generate and print the HTML without building+ # This will still work for basic rendering, though without running the cells+ html = generator.render_html(include_init_island=False)+ print(html)+ # Save the HTML to a file+ output_file = "output.html"+ with open(output_file, "w", encoding="utf-8") as f:+ f.write(html)+ ```++ ///++Any relevant `.html` that gets generated can be run through the [`development.md`](https://github.com/marimo-team/marimo/blob/main/frontend/islands/development.md) file instructions.+### Islands in action!!! warning "Advanced topic!"@@ -286,8 +355,5 @@ In order to use marimo islands, you need to import the necessary JS/CSS headers</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.::: marimo.MarimoIslandGeneratordiff --git a/frontend/islands/development.md b/frontend/islands/development.mdindex 3e607b3d82..fc9922329e 100644--- a/frontend/islands/development.md+++ b/frontend/islands/development.md@@ -1,6 +1,6 @@# Marimo Islands-marimo islands are a way to render HTML "islands" each with static outputs and code. This differs from the normal "app mode" int that there is no top-level app. In "island mode", we do not have access to the HTML of the parent page.+marimo islands are a way to render HTML "islands" each with static outputs and code. This differs from the normal "app mode" in the sense that there is no top-level app. In "island mode", we do not have access to the HTML of the parent page.## Developmentdiff --git a/frontend/package.json b/frontend/package.jsonindex dc5fdc04e4..3c94001130 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -158,7 +158,7 @@"lint:stylelint": "stylelint src/**/*.css --fix","format": "biome format --write .","preview": "vite preview",- "dev:islands": "VITE_MARIMO_ISLANDS=true vite --config islands/vite.config.mts",+ "dev:islands": "cross-env VITE_MARIMO_ISLANDS=true vite --config islands/vite.config.mts","build:islands": "VITE_MARIMO_ISLANDS=true vite --config islands/vite.config.mts build","preview:islands": "VITE_MARIMO_VERSION='0.4.6' VITE_MARIMO_ISLANDS=true vite --config islands/vite.config.mts build","storybook": "storybook dev -p 6006",@@ -200,6 +200,7 @@"autoprefixer": "^10.4.20","babel-plugin-react-compiler": "19.0.0-beta-8a03594-20241020","blob-polyfill": "^7.0.20220408",+ "cross-env": "^7.0.3","eslint": "^8.57.0","eslint-config-prettier": "^9.1.0","eslint-plugin-jsx-a11y": "^6.9.0",diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yamlindex 2170ad737d..a65bb9775e 100644--- a/frontend/pnpm-lock.yaml+++ b/frontend/pnpm-lock.yaml@@ -496,6 +496,9 @@ importers:blob-polyfill:specifier: ^7.0.20220408version: 7.0.20220408+ cross-env:+ specifier: ^7.0.3+ version: 7.0.3eslint:specifier: ^8.57.0version: 8.57.0@@ -4493,6 +4496,11 @@ packages:resolution: {integrity: sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==}+ resolution: {integrity: sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==}+ engines: {node: '>=10.14', npm: '>=6', yarn: '>=1'}+ hasBin: true+resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==}engines: {node: '>= 8'}@@ -13915,6 +13923,10 @@ snapshots:+ dependencies:+ cross-spawn: 7.0.3+dependencies:path-key: 3.1.1diff --git a/marimo/_islands/island_generator.py b/marimo/_islands/island_generator.pyindex 7422fd77b3..b850ef5d3c 100644--- a/marimo/_islands/island_generator.py+++ b/marimo/_islands/island_generator.py@@ -1,7 +1,9 @@# Copyright 2024 Marimo. All rights reserved.from __future__ import annotations+import asyncioimport json+import sysfrom textwrap import dedentfrom typing import TYPE_CHECKING, List, Optional, Union, cast@@ -18,6 +20,9 @@ from marimo._server.file_manager import AppFileManagerfrom marimo._server.file_router import AppFileRouterfrom marimo._utils.marimo_path import MarimoPath+if sys.platform == "win32": # handling for windows+ asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())+if TYPE_CHECKING:from marimo._server.session.session_view import SessionView@@ -152,29 +157,62 @@ class MarimoIslandGenerator:# Example+ Using the MarimoIslandGenerator class:+ ```python+ import asyncio+ import sys+ from marimo import MarimoIslandGenerator++ async def main():+ generator = MarimoIslandGenerator()+ block1 = generator.add_code("import marimo as mo")+ block2 = generator.add_code("mo.md('Hello, islands!')")++ # Build the app+ app = await generator.build()++ # Render the app+ output = f\"\"\"+ <html>+ <head>+ {generator.render_head()}+ </head>+ <body>+ {block1.render(display_output=False)}+ {block2.render()}+ </body>+ </html>+ \"\"\"+ print(output)+ # Save the HTML to a file+ output_file = "output.html"+ with open(output_file, "w", encoding="utf-8") as f:+ f.write(output)++ if __name__ == '__main__':+ asyncio.run(main())+ ```++ You can also create the generator from a file:+```python- from marimo.islands import MarimoIslandGenerator-- generator = MarimoIslandGenerator()- block1 = generator.add_code("import marimo as mo")- block2 = generator.add_code("mo.md('Hello, islands!')")-- # Build the app- app = await generator.build()-- # Render the app- output = f\"\"\"- <html>- <head>- {generator.render_head()}- </head>- <body>- {block1.render(display_output=False)}- {block2.render()}- </body>- </html>- \"\"\"+ from marimo import MarimoIslandGenerator++ # Create the generator from file+ generator = MarimoIslandGenerator.from_file(+ "./<notebook-name>.py", display_code=False+ )++ # Generate and print the HTML without building+ # This will still work for basic rendering, though without running the cells+ html = generator.render_html(include_init_island=False)+ print(html)+ # Save the HTML to a file+ output_file = "output.html"+ with open(output_file, "w", encoding="utf-8") as f:+ f.write(html)```+"""def __init__(self, app_id: str = "main"):