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.

fix: embedding from code (#4052)

Akshay Agrawala6d30e711af3
diff --git a/docs/guides/publishing/playground.md b/docs/guides/publishing/playground.md
index 71040b8ea2..6b11228fe3 100644
--- a/docs/guides/publishing/playground.md
+++ b/docs/guides/publishing/playground.md
@@ -237,10 +237,29 @@ You can optionally render embedded notebooks in read-only mode by appending
### Embedding from code
You can also embed marimo notebook from its string representation (i.e.,
-the notebook file's code), with the URL
+the notebook file's code), using the `code` query parameter:
```
-https://marimo.app?embed=true&show-chrome=false#code/<encoded-uri-component>
+https://marimo.app?embed=true&show-chrome=false&code=<encoded-uri-component>
+```
+
+where `<encoded-uri-component>` is the notebook code URI encoded. For example,
+in JavaScript:
+
+```javascript
+encodeURIComponent(notebookCode)
+```
+
+#### Using lz compression for large notebooks
+
+When using the `code` query parameter, your notebooks must be no greater than `14 KB`.
+For large notebooks, `marimo.app` supports lz-compressed notebook code with a URL hash.
+For example, in JavaScript, you can use the [`lz-string`](https://www.npmjs.com/package/lz-string) package:
+
+```javascript
+import { compressToEncodedURIComponent } from "lz-string";
+
+const url = `https://marimo.app/#code/${compressToEncodedURIComponent(code)}`
```
#### MDX
@@ -250,12 +269,12 @@ For example, if you are using MDX, you can use the following snippet:
```jsx
const MdxNotebook = (props: { code: string }) => {
return (
- <iframe src={`https://marimo.app?embed=true&show-chrome=false#code/${encodeURIComponent(props.code)}`} />
+ <iframe src={`https://marimo.app?embed=true&show-chrome=false&code=${encodeURIComponent(props.code)}`} />
);
};
<MdxNotebook code={`
-import marimo as mo
+import marimo
app = marimo.App()