Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show plots generated with autoviz as part of a marimo notebook does not work #2700

Open
johanneswerner opened this issue Oct 23, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@johanneswerner
Copy link

johanneswerner commented Oct 23, 2024

Describe the bug

I am trying to use Autoviz inside of a marino notebook.

The input dataset is the titanic train dataset from kaggle.

This does not raise any errors, however I cannot convince marimo to show the plots in the notebook. It works with Jupyer Notebooks when adding the %matplotlib inline statement.

Any ideas why this happens and how to fix this?

The environment is set up with poetry. If any additional information is required, I am glad to share it. Thank you very much! marimo is an amazing tool!

Environment

{
  "marimo": "0.9.12",
  "OS": "Linux",
  "OS Version": "6.6.54-2-MANJARO",
  "Processor": "",
  "Python Version": "3.12.6",
  "Binaries": {
    "Browser": "--",
    "Node": "v18.20.4"
  },
  "Dependencies": {
    "click": "8.1.7",
    "docutils": "0.21.2",
    "itsdangerous": "2.2.0",
    "jedi": "0.19.1",
    "markdown": "3.7",
    "narwhals": "1.10.0",
    "packaging": "24.1",
    "psutil": "6.0.0",
    "pygments": "2.18.0",
    "pymdown-extensions": "10.11.2",
    "pyyaml": "6.0.2",
    "ruff": "0.7.0",
    "starlette": "0.41.0",
    "tomlkit": "0.13.2",
    "typing-extensions": "4.12.2",
    "uvicorn": "0.32.0",
    "websockets": "12.0"
  },
  "Optional Dependencies": {
    "altair": "5.4.1",
    "pandas": "2.2.2",
    "polars": "1.5.0"
  }
}

Code to reproduce

import marimo

__generated_with = "0.9.12"
app = marimo.App()


@app.cell
def __():
    import marimo as mo
    return (mo,)


@app.cell
def __():
    import pandas as pd
    import polars as pl

    from autoviz.AutoViz_Class import AutoViz_Class
    return AutoViz_Class, pd, pl


@app.cell
def __(pd):
    df = pd.read_csv("data/train.csv")
    return (df,)


@app.cell
def __(df):
    df
    return


@app.cell
def __(AutoViz_Class, df):
    AV = AutoViz_Class()
    AV.AutoViz(df, depVar="Survived", chart_format="png")
    return (AV,)


@app.cell
def __():
    return


if __name__ == "__main__":
    app.run()
@johanneswerner johanneswerner added the bug Something isn't working label Oct 23, 2024
@mscolnick
Copy link
Contributor

mscolnick commented Oct 23, 2024

I am not sure what the desired output is supposed to look like, but you can convert it to Html to rendering inside marimo.

mo.Html(AV.AutoViz(df, depVar="Survived", chart_format="png").to_html())

We have some documentation on how to display/format rich objects, such as AutoViz, https://docs.marimo.io/guides/integrating_with_marimo/displaying_objects.html

@johanneswerner
Copy link
Author

Thank you very much. The issue did not solve with mo.Html, I am not sure where the output is captured but it does not end up in the marimo UI. If you are running the same code cells in a jupyter notebook, you can see that the plots appear as part of the jupyter notebook. If it helps, I can also create an share the jupyter notebook.

@mscolnick
Copy link
Contributor

@johanneswerner, a jupyter notebook would be great. can you also screenshot what you currently see when doing mo.Html(...to_html())?

@johanneswerner
Copy link
Author

Since github does not allow me to upload a jupyter notebook file to a comment, here is the content

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import polars as pl\n",
    "\n",
    "from autoviz.AutoViz_Class import AutoViz_Class"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(\"data/train.csv\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "AV = AutoViz_Class()\n",
    "AV.AutoViz(df, depVar=\"Survived\", verbose=2, chart_format=\"png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}

When I am running the notebook, it produces plots after the last command.

With marimo, it does not show the plots, see screenshot below

Image

and at the end of the textarea

Image

Further information: I am using poetry here and it seems nltk (used for word cloud plots) has problems finding the source path for the nltk data (which ends up in my home folder, not in my environment folder) - but even without nltk, Autoviz should still be able to create plots that are not depending on nltk (which are produced but not showing inline in the plot).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants