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.

improvement: Add include-code=false query param for static notebooks to hide the code (#820)

Myles Scolnickb5e2b5814747
diff --git a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx
index 3692a1e326..649882208c 100644
--- a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx
+++ b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx
@@ -28,8 +28,21 @@ const VerticalLayoutRenderer: React.FC<VerticalLayoutProps> = ({
// Default to showing code if the notebook is static
return isStaticNotebook();
});
- // Show code if there is at least one cell with code
- const canShowCode = mode === "read" && cells.some((cell) => cell.code);
+ const evaluateCanShowCode = () => {
+ const cellsHaveCode = cells.some((cell) => cell.code);
+
+ // Only show code if in read mode and there is at least one cell with code
+
+ // If it is a static-notebook or wasm-read-only-notebook, code is always included,
+ // but it can be turned it off via a query parameter (include-code=false)
+
+ const urlParams = new URLSearchParams(window.location.search);
+ const includeCode = urlParams.get("include-code");
+ return mode === "read" && includeCode !== "false" && cellsHaveCode;
+ };
+
+ const canShowCode = evaluateCanShowCode();
+
return (
<VerticalLayoutWrapper invisible={invisible} appConfig={appConfig}>
{cells.map((cell) => (
diff --git a/frontend/src/core/pyodide/utils.ts b/frontend/src/core/pyodide/utils.ts
index 3b4dcca63c..93549753f6 100644
--- a/frontend/src/core/pyodide/utils.ts
+++ b/frontend/src/core/pyodide/utils.ts
@@ -1,4 +1,8 @@
/* Copyright 2024 Marimo. All rights reserved. */
+
+/**
+ * Whether the current environment is Pyodide/WASM
+ */
export function isPyodide() {
return document.querySelector("marimo-wasm") !== null;
}