marimo icon indicating copy to clipboard operation
marimo copied to clipboard

Add support for `pygwalker` data visualization tool

Open Haleshot opened this issue 1 year ago • 6 comments

Describe the bug

Tried a very sample demo with a sample code from the pygwalker repo; it resulted in:

Unsupported mimetype: application/vnd.jupyter.widget-view+json

being displayed on top of the cell block.

Would having this data visualization tool integrated into marimo be encouraged?

Some screenshots to support:

In marimo: marimo-demo

In Jupyter labs (from pygwalker repo):

Environment

{
  "marimo": "0.8.19",
  "OS": "Windows",
  "OS Version": "11",
  "Processor": "AMD64 Family 25 Model 80 Stepping 0, AuthenticAMD",
  "Python Version": "3.11.4",
  "Binaries": {
    "Browser": "128.0.6613.120",
    "Node": "v18.17.0"
  },
  "Dependencies": {
    "click": "8.1.7",
    "importlib-resources": "6.4.5",
    "jedi": "0.19.1",
    "markdown": "3.6",
    "pygments": "2.18.0",
    "pymdown-extensions": "10.8.1",
    "ruff": "0.6.0",
    "starlette": "0.37.2",
    "tomlkit": "0.12.5",
    "typing-extensions": "4.12.2",
    "uvicorn": "0.29.0",
    "websockets": "12.0"
  },
  "Optional Dependencies": {
    "altair": "5.4.1",
    "duckdb": "1.1.1",
    "pandas": "2.2.2",
    "pyarrow": "17.0.0"
  }
}

Code to reproduce

Import pygwalker and pandas to your Jupyter Notebook to get started.

import pandas as pd
import pygwalker as pyg

You can use pygwalker without breaking your existing workflow. For example, you can call up PyGWalker with the dataframe loaded in this way:

df = pd.read_csv('filename.csv')
walker = pyg.walk(df)

Haleshot avatar Oct 03 '24 08:10 Haleshot

Would like to ask how this issue can be tackled; something to do solely with adding/handling mimetypes in marimo.

Haleshot avatar Oct 03 '24 08:10 Haleshot

@Haleshot, quick solution is we can by outputting the HTML

import pygwalker as pyg
import marimo as mo
from vega_datasets import data

walker = pyg.walk(data.iris())
mo.iframe(walker.to_html_without_iframe())

It should return a mime type of HTML as well, but looks like it doesn't. I can look if we can support this though.

mscolnick avatar Oct 03 '24 13:10 mscolnick

@Haleshot could you actually file a feature request on the pywalker repo so that pygwalker.api.pygwalker.PygWalker could implement a _repr_html_ or _mime_ (see docs), otherwise looks like this:

image

mscolnick avatar Oct 03 '24 13:10 mscolnick

@Haleshot, quick solution is we can by outputting the HTML

import pygwalker as pyg
import marimo as mo
from vega_datasets import data

walker = pyg.walk(data.iris())
mo.iframe(walker.to_html_without_iframe())

It should return a mime type of HTML as well, but looks like it doesn't. I can look if we can support this though.

When trying this; I thought doing something relating to anywidget might lead to a successful output.

Haleshot avatar Oct 03 '24 13:10 Haleshot

@Haleshot could you actually file a feature request on the pywalker repo so that pygwalker.api.pygwalker.PygWalker could implement a _repr_html_ or _mime_ (see docs), otherwise looks like this:

image

Sure, will check this out and raise a feature request there!

Haleshot avatar Oct 03 '24 13:10 Haleshot

Linking the relevant issue request here - https://github.com/Kanaries/pygwalker/issues/638

Haleshot avatar Oct 03 '24 14:10 Haleshot

Closing this issue as pygwalker support was added to marimo!

Relevant links:

  1. https://github.com/Kanaries/pygwalker/issues/638
  2. https://github.com/Kanaries/pygwalker/pull/647
  3. https://github.com/Kanaries/pygwalker/pull/649

Thanks to everyone who helped in this integration.

Relevant SS:

image

Sample code for anyone who wants to try:

# /// script
# requires-python = ">=3.11"
# dependencies = [
#     "marimo",
#     "pandas==2.2.3",
#     "pygwalker==0.4.9.12",
#     "openai==1.52.2",
#     "polars==1.12.0",
# ]
# ///

import marimo

__generated_with = "0.9.14"
app = marimo.App(width="medium")


@app.cell
def __(pd, walk):
    _df = pd.read_csv("../Exploratory-Data-Analysis/assets/books_enriched.csv")

    walk(_df, spec="spec.json")
    return


@app.cell
def __(pd, pyg):
    _df = pd.read_csv("../Exploratory-Data-Analysis/assets/books_enriched.csv")
    pyg.walk(_df, spec="spec.json")
    return


@app.cell(hide_code=True)
def __():
    # import libraries
    import marimo as mo
    import pandas as pd
    from pygwalker.api.marimo import walk
    import pygwalker.api.marimo as pyg
    return mo, pd, pyg, walk


if __name__ == "__main__":
    app.run()

Haleshot avatar Oct 29 '24 06:10 Haleshot