diff --git a/marimo/_output/formatters/formatters.py b/marimo/_output/formatters/formatters.py index 81ced8473a7..3a30a6e4a46 100644 --- a/marimo/_output/formatters/formatters.py +++ b/marimo/_output/formatters/formatters.py @@ -25,6 +25,7 @@ from marimo._output.formatters.panel_formatters import PanelFormatter from marimo._output.formatters.plotly_formatters import PlotlyFormatter from marimo._output.formatters.pyecharts_formatters import PyechartsFormatter +from marimo._output.formatters.pygwalker_formatters import PygWalkerFormatter from marimo._output.formatters.seaborn_formatters import SeabornFormatter from marimo._output.formatters.structures import StructuresFormatter from marimo._output.formatters.sympy_formatters import SympyFormatter @@ -39,6 +40,7 @@ PandasFormatter.package_name(): PandasFormatter(), PolarsFormatter.package_name(): PolarsFormatter(), PyArrowFormatter.package_name(): PyArrowFormatter(), + PygWalkerFormatter.package_name(): PygWalkerFormatter(), PlotlyFormatter.package_name(): PlotlyFormatter(), SeabornFormatter.package_name(): SeabornFormatter(), LeafmapFormatter.package_name(): LeafmapFormatter(), diff --git a/marimo/_output/formatters/pygwalker_formatters.py b/marimo/_output/formatters/pygwalker_formatters.py new file mode 100644 index 00000000000..45b6db62150 --- /dev/null +++ b/marimo/_output/formatters/pygwalker_formatters.py @@ -0,0 +1,24 @@ +# Copyright 2024 Marimo. All rights reserved. +from __future__ import annotations + +from marimo._output.formatters.formatter_factory import FormatterFactory +from marimo._runtime.context.utils import running_in_notebook + + +class PygWalkerFormatter(FormatterFactory): + @staticmethod + def package_name() -> str: + return "pygwalker" + + def register(self) -> None: + if running_in_notebook(): + # monkey-patch pygwalker.walk to work in marimo; + # older versions of marimo may not have api.marimo, and not sure + # about pygwalker's API stability, so use a coarse try/except + try: + import pygwalker # type: ignore + from pygwalker.api.marimo import walk # type: ignore + + pygwalker.walk = walk # type: ignore + except Exception: + pass diff --git a/marimo/_smoke_tests/pygwalker_test.py b/marimo/_smoke_tests/pygwalker_test.py new file mode 100644 index 00000000000..36c5174622c --- /dev/null +++ b/marimo/_smoke_tests/pygwalker_test.py @@ -0,0 +1,23 @@ +import marimo + +__generated_with = "0.9.14" +app = marimo.App(width="medium") + + +@app.cell +def __(): + import pygwalker + + from vega_datasets import data + return data, pygwalker + + +@app.cell +def __(data, pygwalker): + df = data.iris() + pygwalker.walk(df) + return (df,) + + +if __name__ == "__main__": + app.run()