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

Bokeh figure axes collapse on dynamic creation #5561

Open
cdeil opened this issue Sep 30, 2023 · 2 comments
Open

Bokeh figure axes collapse on dynamic creation #5561

cdeil opened this issue Sep 30, 2023 · 2 comments
Labels
bokeh Request is for change in bokeh

Comments

@cdeil
Copy link
Contributor

cdeil commented Sep 30, 2023

With Bokeh 3.2.2 and Panel 1.3.0a3 (but also earlier versions I think since Panel 1.0) we saw a bug where Bokeh figure axes sometimes collapse in the case where the figure is created dynamically on widget interaction.

We see this in Panel apps and an example is below. But it might very well be a Bokeh bug, e.g. bokeh/bokeh#13340 sounds similar and overall this looks like a state synchronisation or race condition bug.


Screenshot showing collapsed axes:

Screenshot 2023-09-30 at 11 37 27

To reproduce the bug, run this with panel serve and the in the browser drag a bit the two sliders to see the bug come and go.
It can probably be simplified further, e.g. bokeh/bokeh#13340 already shows a Bokeh-only bug that might be related.

import numpy as np
import pandas as pd
import bokeh
import panel as pn


def make_one_figure(n_points, width, height, start="2023-01-01", end="2023-12-31"):
    rng = np.random.default_rng()
    x = pd.date_range(start=start, end=end, periods=n_points, tz="utc")
    y = rng.random(n_points)
    df = pd.DataFrame({"x": x, "y": y})
    p = bokeh.plotting.figure(width=width, height=height, x_axis_type="datetime")
    p.step(x="x", y="y", source=df)
    return p


def make_many_figures(n_figures=3, n_points=1000, width=500, height=100):
    col = pn.Column("# Plots", sizing_mode="stretch_both")
    for _ in range(n_figures):
        fig = make_one_figure(n_points, width, height)
        col.append(fig)
    return col


def make_app():
    n_figures = pn.widgets.IntSlider(name="n_figures", start=0, end=10, value=3)
    n_points = pn.widgets.IntSlider(name="n_points", start=0, end=1000, value=100)
    main = pn.bind(make_many_figures, n_figures, n_points)

    pn.extension(template="material")
    template = pn.template.MaterialTemplate(title="Lotsa plots")
    template.sidebar[:] = [n_figures, n_points]
    template.main.append(main)

    return template


app = make_app()
app.show()

Often the bug (figure collapse) occurs but no warning or error in the panel server terminal or web browser console.

--

Sometimes a warning or error does occur though that might give you a hint at the root couse of the issue:

Warning:

[bokeh] could not set initial ranges

Error:

RuntimeError: _pending_writes should be non-None when we have a document lock, and we should have the lock when the document changes

Screenshots:

Screenshot 2023-09-30 at 11 43 01 Screenshot 2023-09-30 at 11 42 25 Screenshot 2023-09-30 at 11 41 50
@philippjfr philippjfr added the bokeh Request is for change in bokeh label Sep 30, 2023
@cdeil
Copy link
Contributor Author

cdeil commented Mar 23, 2024

In our app we no longer see this issue after we changed to class-based views.

However for the example app above with panel 1.4.0rc4 and bokeh 3.4.0 if I drag the sliders I still get errors sometimes.

So might still be a bug in Panel or Bokeh affecting such apps.

Screenshot 2024-03-23 at 12 52 11 Screenshot 2024-03-23 at 12 52 55

@philippjfr
Copy link
Member

Thanks, that's pretty bizarre. Not sure how a stylesheet can end up without a URL but I can put a guard around that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bokeh Request is for change in bokeh
Projects
None yet
Development

No branches or pull requests

2 participants