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_NO_JS is more agressive about formatters (#4737)
Dylan Madisetti412a0741f8a9
diff --git a/marimo/_islands/_island_generator.py b/marimo/_islands/_island_generator.pyindex 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.pyindex 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 nwfrom 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.pyindex 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 annotationsimport json+import osimport tracebackfrom dataclasses import dataclassfrom 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 formattersif 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()