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
gr.Plot()
injected multiple Bokeh js scripts, breaking Bokeh.Models
#5449
Comments
Ugly fix: function load_bokeh(): HTMLScriptElement {
let script = document.getElementById('gr-bokeh');
if (script !== null) return script;
script = document.createElement("script");
...
script.id = 'gr-bokeh';
return script;
} and similarly for |
Hi @relubwu I can't reproduce this issue. In your repro, I tried creating my own repro by modifying import gradio as gr
import xyzservices.providers as xyz
from bokeh.tile_providers import get_provider
from bokeh.models import ColumnDataSource, Whisker
from bokeh.plotting import figure
from bokeh.sampledata.autompg2 import autompg2 as df
from bokeh.sampledata.penguins import data
from bokeh.transform import factor_cmap, jitter, factor_mark
def get_plot(plot_type):
if plot_type == "map":
tile_provider = get_provider(xyz.OpenStreetMap.Mapnik)
plot = figure(
x_range=(-2000000, 6000000),
y_range=(-1000000, 7000000),
x_axis_type="mercator",
y_axis_type="mercator",
)
plot.add_tile(tile_provider)
return plot
elif plot_type == "whisker":
classes = list(sorted(df["class"].unique()))
p = figure(
height=400,
x_range=classes,
background_fill_color="#efefef",
title="Car class vs HWY mpg with quintile ranges",
)
p.xgrid.grid_line_color = None
g = df.groupby("class")
upper = g.hwy.quantile(0.80)
lower = g.hwy.quantile(0.20)
source = ColumnDataSource(data=dict(base=classes, upper=upper, lower=lower))
error = Whisker(
base="base",
upper="upper",
lower="lower",
source=source,
level="annotation",
line_width=2,
)
error.upper_head.size = 20
error.lower_head.size = 20
p.add_layout(error)
p.circle(
jitter("class", 0.3, range=p.x_range),
"hwy",
source=df,
alpha=0.5,
size=13,
line_color="white",
color=factor_cmap("class", "Light6", classes),
)
return p
elif plot_type == "scatter":
SPECIES = sorted(data.species.unique())
MARKERS = ["hex", "circle_x", "triangle"]
p = figure(title="Penguin size", background_fill_color="#fafafa")
p.xaxis.axis_label = "Flipper Length (mm)"
p.yaxis.axis_label = "Body Mass (g)"
p.scatter(
"flipper_length_mm",
"body_mass_g",
source=data,
legend_group="species",
fill_alpha=0.4,
size=12,
marker=factor_mark("species", MARKERS, SPECIES),
color=factor_cmap("species", "Category10_3", SPECIES),
)
p.legend.location = "top_left"
p.legend.title = "Species"
return p
with gr.Blocks() as demo:
with gr.Row():
plot_type = gr.Radio(value="scatter", choices=["scatter", "whisker", "map"])
plot = gr.Plot()
plot2 = gr.Plot()
plot_type.change(get_plot, inputs=[plot_type], outputs=[plot])
plot_type.change(get_plot, inputs=[plot_type], outputs=[plot2])
demo.load(get_plot, inputs=[plot_type], outputs=[plot])
if __name__ == "__main__":
demo.launch() but it works fine. Can you advise? |
Hi @abidlabs , I tried repro the issue with the code you provided in a clean Colab notebook, and the issue persists. Steps:
Please let me know if this helps clarify the issue! |
Might be a bug in this line. Bokeh should in theory only be loaded once: gradio/js/plot/static/Plot.svelte Line 57 in f09aea3
|
Hi @freddyaboulton , great catch! I tried playing around with this flag a bit, it seems not updated in time when Bokeh stuff was injected. |
Yup that's what I'm seeing as well |
Hey @abidlabs ! Can confirm fix works: |
Describe the bug
When
gr.Plot()
is called more than once,load_bokeh()
inPlot.svelte
would inject Bokeh dependencies multiple times to the frontend document. This causes some conflict on the Bokeh side and subsequently causes 66 models missing fromBokeh.Models._known_models
Have you searched existing issues? 🔎
Reproduction
Bokeh.Models._known_models
on the frontend, you'll see 366 models loaded.gr.Plot()
:The first plot component would collapse due to
Error: could not resolve type 'DataTable', which could be due to a widget or a custom model not being registered before first usage
. NowBokeh.Models._known_models
only shows 300 models loaded, missing 66.load_bokeh
andload_plugins
injs/plot/static/Plot.svelte
Screenshot
No response
Logs
No response
System Info
Severity
Blocking usage of gradio (at least for me :( )
The text was updated successfully, but these errors were encountered: