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

Issue with interactions between widgets and plots using bokeh server #4764

Closed
troianow opened this issue Jul 6, 2016 · 15 comments
Closed

Issue with interactions between widgets and plots using bokeh server #4764

troianow opened this issue Jul 6, 2016 · 15 comments

Comments

@troianow
Copy link

@troianow troianow commented Jul 6, 2016

When creating two plots, each one with select box acting on the data and try to replace the plot in the "on_change" callback, the change in one select box updates the corresponding plot and messes up the other (the plot disappears or some text appears behind, ...).

To reproduce the issue, simply run the code below as server and change the selection of the first select box. The first graph will update and the second will get affected. Then, changing the second select box fixes the display of the second plot and affects the first one.

from bokeh import layouts
from bokeh.io import curdoc
from bokeh.sampledata import iris
from bokeh.models import ColumnDataSource, widgets
from bokeh.plotting import figure


df = iris.flowers

species = df.species.unique().tolist()
COLORS = [
    "green", "red",  "blue", "cyan",
    "purple", "magenta", "orange", 'darkgray', 'navy', 'brown'
]

df['color'] = df['species'].apply(lambda x: COLORS[species.index(x)])
df.head()


def get_figure(min_length):
    min_length = int(min_length)
    p = figure(title="markers.py example")
    source = ColumnDataSource(df[df.sepal_length >= min_length])
    p.scatter(x='sepal_width', y='sepal_length', color='color', source=source)
    return p


def make_combo():
    w = widgets.Select(options=['2', '4', '6'], value='2')
    fig = get_figure(2)
    c = layouts.Column(w, fig)

    def update(name, old, new):
        c.children[-1] = get_figure(w.value)

    w.on_change('value', update)
    return c


layout_ = layouts.layout([make_combo()], [make_combo()])
curdoc().add_root(layout_)

Output of bokeh info:

Python version      :  3.4.3 |Continuum Analytics, Inc.| (default, Dec  1 2015, 11:59:33) [MSC v.1600 32 bit (Intel)]
IPython version     :  4.0.0
Bokeh version       :  0.12.0
BokehJS static path :  c:\PyEnv\py34_32\20160511\lib\site-packages\bokeh\server\static
@bryevdv
Copy link
Member

@bryevdv bryevdv commented Jul 6, 2016

Here's a screenshot. My guess is that a resize event needs to be triggered but is not.

screen shot 2016-07-06 at 6 24 05 pm

@bryevdv bryevdv added the type: bug label Jul 6, 2016
@bryevdv bryevdv added this to the short-term milestone Jul 6, 2016
@bryevdv
Copy link
Member

@bryevdv bryevdv commented Jul 6, 2016

I was hoping this might be a workaround but unfortunately not:

   def update(name, old, new):
        new_children = c.children
        new_children[-1] = get_figure(w.value)
        c.children = new_children

@troianow Is it the same kind of plot (glyphs, etc) but just the data is changing? A current workaround would be to update the data in the plot, instead of the plot itself, as demonstrated in most of the existing examples

@bryevdv
Copy link
Member

@bryevdv bryevdv commented Jul 6, 2016

Aso FWIW I don't think the widgets are relevant I think it is just the replacement of a child plot at all that is problematic.

@troianow
Copy link
Author

@troianow troianow commented Jul 7, 2016

@bryevdv Unfortunately, for my application, most of the plot changes: the widget might control the way the data is sliced, thus impacting the glyphs, axes, legend, ... so I don't think I can get away with changes in the data source alone. Is there a good way to replace everything in the figure without replacing the figure itself?

@bryevdv
Copy link
Member

@bryevdv bryevdv commented Jul 7, 2016

OK, we will make a priority of it, but the best person to try and fix this is out for another week or so, so it will probably not be able to be fixed until after SciPy.

@troianow
Copy link
Author

@troianow troianow commented Aug 1, 2016

Is someone looking at this?

@birdsarah
Copy link
Member

@birdsarah birdsarah commented Aug 1, 2016

Not that I'm aware of. Are you experiencing the same issue with 0.12.1?

@troianow
Copy link
Author

@troianow troianow commented Aug 2, 2016

Yes, the behavior is the same

@migueldiasalmeida
Copy link

@migueldiasalmeida migueldiasalmeida commented Oct 22, 2016

I am having the same issue. Also with column if I define multiple rows.

The usage of row was my workaround and with only one row it's working for me (or one column). So troianow, this may be the solution for you. As I need a grid like structure with a toolbar per plot I do need this fixed.

@tobyhodges
Copy link
Contributor

@tobyhodges tobyhodges commented Nov 24, 2016

I've been bumping my head against this bug today also. Discussion group post here, which contains a link to a Gist of code to reproduce the problem. Just in case a second example is helpful.

@mbrigdan
Copy link

@mbrigdan mbrigdan commented Dec 9, 2016

Facing the same problem. I thought using the layout(...) function to create the grid might solve it, but no luck.

My current workaround is to add my "real" layout inside a one element column which acts as the root. When I want to update, I remove the real layout, then add the updated on back into the root. Has the downside of noticeably clearing the whole page when it happens, but works for now.

(As a side note that I discovered while working around this, is there a reported bug for curdoc().clear() not clearing the page? My first attempt was to clear it then add a new root, but it just duplicated everything. Or is this behaviour intentional?)

@bryevdv
Copy link
Member

@bryevdv bryevdv commented Mar 1, 2017

I think this and #5518 may be related or possibly the same root cause

@mattpap
Copy link
Contributor

@mattpap mattpap commented Mar 11, 2017

Good news is that his isn't a server issue. Any PATCH-DOC errors or even most unknown edit variable and constraints don't contribute to the failures we can visually observe in this and other related issues (#5518, #5967, ...). Those are side effects of poor memory management and old models and views interacting with server and layout, rendering, triggering events.

The core issue here is that updating a layout, even if the model tree after update is the same and just ids are different, results in a smaller set of layout constraints. Usually 2 or 3 constraints are missing per plot. Those 2 constraints are most likely related to width and height as those are set to 0 for some of plots after update. It's a bit worrying that it can be 2 or 3, which is undeterministic, but not unexpected knowing how constraints are "collected". This and events triggering left and right explains also why initialization is so slow and layouts with many plots pretty much unresponsive.

I did some preliminary work to fix this in PR #5976.

@bryevdv bryevdv modified the milestones: 0.12.5, 0.12.6 Mar 23, 2017
@nickmachairas
Copy link

@nickmachairas nickmachairas commented May 1, 2017

Hello everyone! First time commenting but I've been closely following development, I'm a big supporter of the bokeh package, fantastic job done.

I am having problems as well with updating multiple plots with a callback function arranged with the layout function. I was getting DeserializationErrors in version 0.12.2, bokeh serve was hanging in 0.12.5. However, the plots are updating with the callback in dev version 0.12.6 but I had to nest each plot separately in column functions. It works but I see multiple RuntimeErrors in the console.

I can help with testing if needed. Thanks

@bryevdv
Copy link
Member

@bryevdv bryevdv commented Jun 1, 2017

@mattpap I think this is the same issue (or related to #4810) basically, adding new models that have references to other models (such as new plots) results in

2017-05-31 20:02:20,720 error handling message Message 'PATCH-DOC' (revision 1): RuntimeError('Cannot apply patch to d3a4b88c-321d-4bdf-8d61-e62bbe0d9f10 which is not in the document',)

In this case, the plots render, but the toolbar does not. My guess is that patches are not being handled carefully enough in the presence of object graphs. I think it's trying to patch sub objects like new toolbar before they are actually instantiated (speculation)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Linked pull requests

Successfully merging a pull request may close this issue.

8 participants
You can’t perform that action at this time.