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

Fix Plotly and Altair plots in 5.0-dev branch #9418

Closed
abidlabs opened this issue Sep 23, 2024 · 2 comments
Closed

Fix Plotly and Altair plots in 5.0-dev branch #9418

abidlabs opened this issue Sep 23, 2024 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@abidlabs
Copy link
Member

No description provided.

@abidlabs abidlabs added this to the Gradio 5 milestone Sep 23, 2024
@abidlabs abidlabs added the bug Something isn't working label Sep 23, 2024
@whitphx
Copy link
Member

whitphx commented Sep 24, 2024

hmm it's a general bug on gr.Plot, not a Lite specific?

import gradio as gr
import numpy as np
import plotly.express as px
import pandas as pd

countries = ["USA", "Canada", "Mexico", "UK"]

def fn():
    df = pd.DataFrame({
        "day": np.arange(0, 100)
    })

    fig = px.line(df)

    return fig


demo = gr.Interface(
    fn=fn,
    inputs=None,
    outputs=gr.Plot()
)

demo.launch()

CleanShot 2024-09-24 at 14 05 36@2x

CleanShot 2024-09-24 at 14 06 12@2x

I'm investigating this problem in #9422

@whitphx
Copy link
Member

whitphx commented Sep 24, 2024

  • This error is not Lite specific.
    • I wonder why the normal E2E tests are passing.
  • It was introduced in Ssr part 2 #9339 as described below.

Reproduce the error

These are tested on the normal Gradio, not Lite.

import gradio as gr
import numpy as np
import pandas as pd
import plotly.express as px
from matplotlib import pyplot as plt


df = pd.DataFrame({
    "data": np.random.rand(100)
})

# Matplotlib plot works.
# fig = plt.figure()
# plt.plot(df["data"])

# Plotly plot causes error.
fig = px.line(df)

demo = gr.Interface(
    fn=lambda: None,
    inputs=gr.Plot(value=fig),
    outputs=None,
)

demo.launch()

8e52b6a (4c8c6f2^): It was working.
CleanShot 2024-09-24 at 17 01 58@2x


4c8c6f2: It started to fail.

CleanShot 2024-09-24 at 17 06 55@2x
CleanShot 2024-09-24 at 17 07 15@2x

This rev had another SSR error below, which is now fixed, btw.

ReferenceError: self is not defined
    at file:///Users/whitphx/ghq/github.com/gradio-app/gradio/gradio/templates/node/build/server/chunks/PlotlyPlot-BCAN8zg5.js:19:39
    at requirePlotly_min (file:///Users/whitphx/ghq/github.com/gradio-app/gradio/gradio/templates/node/build/server/chunks/PlotlyPlot-BCAN8zg5.js:20:4)
    at file:///Users/whitphx/ghq/github.com/gradio-app/gradio/gradio/templates/node/build/server/chunks/PlotlyPlot-BCAN8zg5.js:24:1
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)

Current HEAD of 5.0-dev, 74f3b9d: It's still failing.
CleanShot 2024-09-24 at 17 10 09@2x
CleanShot 2024-09-24 at 17 10 25@2x


The released PyPI package (gradio==5.0.0b3): It also fails. This was wrong. It's working.

Reason

Found that $_layout in Blocks.svelte contains weird values in $_layout.children[]...children[].props as below. As there is $_layout.children[]...children[].props.target == {}, which is passed down to <Render> as this, it overrides the proper target prop there with an invalid value {}, then it's passed to each component and caused the problem, e.g. calling target.appendChild() that doesn't exist in PlotlyPlot.svelte.
(So #9422 can be the workaround but it doesn't solve the actual problem of setting the weird values.)

CleanShot 2024-09-24 at 18 05 44@2x
This screenshot was taken by adding $: console.log({ $_layout });.

I couldn't find where such weird value is set to $_layout but changes on Blocks.svelte in ##9339 is related? Any idea @pngwn ?

@whitphx whitphx changed the title Fix plots for @gradio/lite in 5.0-dev branch Fix Plotly and Altair plots in 5.0-dev branch Sep 24, 2024
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

3 participants