Skip to content

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

Closed

Description

@gtroianowski

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

Activity

  1. bryevdv commented on Jul 6, 2016

    @bryevdv
    Member

    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

  2. added this to the milestone on Jul 6, 2016
  3. bryevdv commented on Jul 6, 2016

    @bryevdv
    Member

    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

  4. bryevdv commented on Jul 6, 2016

    @bryevdv
    Member

    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.

  5. gtroianowski commented on Jul 7, 2016

    @gtroianowski
    Author

    @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?

  6. bryevdv commented on Jul 7, 2016

    @bryevdv
    Member

    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.

  7. gtroianowski commented on Aug 1, 2016

    @gtroianowski
    Author

    Is someone looking at this?

  8. birdsarah commented on Aug 1, 2016

    @birdsarah
    Member

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

  9. gtroianowski commented on Aug 2, 2016

    @gtroianowski
    Author

    Yes, the behavior is the same

  10. migueldiasalmeida commented on Oct 22, 2016

    @migueldiasalmeida

    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.

  11. tobyhodges commented on Nov 24, 2016

    @tobyhodges
    Contributor

    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.

  12. mbrigdan commented on Dec 9, 2016

    @mbrigdan

    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?)

  13. modified the milestones: 0.12.5, on Dec 9, 2016
  14. 6 remaining items

  15. modified the milestones: 0.12.6, 0.12.5 on Mar 23, 2017
  16. nickmachairas commented on May 1, 2017

    @nickmachairas

    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

  17. bryevdv commented on Jun 1, 2017

    @bryevdv
    Member

    @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)

  18. modified the milestones: 0.12.6, 0.12.7 on Jun 6, 2017
  19. modified the milestones: 0.12.6, 0.12.7 on Jun 9, 2017
  20. github-actions commented on Oct 28, 2024

    @github-actions

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  21. locked as resolved and limited conversation to collaborators on Oct 28, 2024
  22. added theissue type on Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions