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: MARIMO_NO_JS is more agressive about formatters (#4737)

Dylan Madisetti412a0741f8a9
diff --git a/marimo/_islands/_island_generator.py b/marimo/_islands/_island_generator.py
index 5a37cdb37d..505ef4e714 100644
--- a/marimo/_islands/_island_generator.py
+++ b/marimo/_islands/_island_generator.py
@@ -69,6 +69,7 @@ class MarimoIslandStub:
display_code: Optional[bool] = None,
display_output: Optional[bool] = None,
is_reactive: Optional[bool] = None,
+ as_raw: bool = False,
) -> str:
"""
Render the HTML island code for the cell.
@@ -79,6 +80,7 @@ class MarimoIslandStub:
- display_code (bool): Whether to display the code in HTML.
- display_output (bool): Whether to include the output in the HTML.
- is_reactive (bool): Whether this code block will run with pyodide.
+ - as_raw (bool): Removes some of the HTML to directly include the data.
*Returns:*
@@ -122,6 +124,21 @@ class MarimoIslandStub:
"</marimo-cell-code>"
)
+ if as_raw:
+ # If as_raw is True, output as raw values as possible.
+ # Used primarily for cases with no js (like pdfs)
+ released = (
+ output.text.encode().decode("unicode_escape")
+ if output and display_output
+ else ""
+ )
+ return dedent(
+ f"""
+ {released}
+ {code_block}
+ """
+ ).strip()
+
# Cell may not have output
# (e.g. imports, but still needs to be included)
return remove_empty_lines(
diff --git a/marimo/_output/formatters/df_formatters.py b/marimo/_output/formatters/df_formatters.py
index 2acdf1839f..971f22371b 100644
--- a/marimo/_output/formatters/df_formatters.py
+++ b/marimo/_output/formatters/df_formatters.py
@@ -1,6 +1,8 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
+import os
+
import narwhals.stable.v1 as nw
from marimo import _loggers
@@ -19,6 +21,9 @@ def include_opinionated() -> bool:
runtime_context_installed,
)
+ if os.getenv("MARIMO_NO_JS", "false").lower() == "true":
+ return False
+
if runtime_context_installed():
ctx = get_context()
return ctx.marimo_config["display"]["dataframes"] == "rich"
diff --git a/marimo/_output/formatting.py b/marimo/_output/formatting.py
index d3cd429b64..ec6fc06629 100644
--- a/marimo/_output/formatting.py
+++ b/marimo/_output/formatting.py
@@ -18,6 +18,7 @@ taking precedence over the MIME protocol.
from __future__ import annotations
import json
+import os
import traceback
from dataclasses import dataclass
from html import escape
@@ -96,7 +97,7 @@ def get_formatter(
obj: T,
# Include opinionated formatters by default
# (e.g., for pandas, polars, arrow, etc.)
- include_opinionated: bool = True,
+ include_opinionated: Optional[bool] = None,
) -> Optional[Formatter[T]]:
from marimo._runtime.context import ContextNotInitializedError, get_context
@@ -112,6 +113,12 @@ def get_formatter(
# a kernel (eg, in a unit test or when run as a Python script)
register_formatters()
+ # If not explicitly opinionated, we defer to the environment.
+ if include_opinionated is None:
+ include_opinionated = (
+ os.getenv("MARIMO_NO_JS", "false").lower() == "false"
+ )
+
# Plain opts out of opinionated formatters
if isinstance(obj, Plain):
child_formatter = get_formatter(obj.child, include_opinionated=False)
@@ -179,7 +186,9 @@ class FormattedOutput:
return FormattedOutput(mimetype="text/plain", data="")
-def try_format(obj: Any, include_opinionated: bool = True) -> FormattedOutput:
+def try_format(
+ obj: Any, include_opinionated: Optional[bool] = None
+) -> FormattedOutput:
if obj is None:
return FormattedOutput.empty()