-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Monkey-patch pygwalker.walk when running in a marimo notebook to point to pygwalker.api.marimo.walk, so that pygwalker code examples from the wild work automatically.
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# 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 | ||
from pygwalker.api.marimo import walk | ||
|
||
pygwalker.walk = walk # type: ignore | ||
except Exception: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |