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

[BUG] fig.add_layout doesn't update the figure. #8862

Closed
smamyris opened this issue Apr 23, 2019 · 4 comments · Fixed by #9928
Closed

[BUG] fig.add_layout doesn't update the figure. #8862

smamyris opened this issue Apr 23, 2019 · 4 comments · Fixed by #9928

Comments

@smamyris
Copy link

smamyris commented Apr 23, 2019

Environment:
Python 3.5
Bokeh 1.1.0
Tornado 6.0.2

Running a Bokeh server, in 1.0.3 the following code snippet adds a span and box annotation to fig whenever button is clicked. In 1.1.0 the on_click event still runs, but fig doesn't update.
I didn't see anything related in the release notes, so I assume this is not the intended behavior.
I would appreciate any feedback on whether this is reproducible on other machines and potential workarounds.

from bokeh.plotting import Figure
from bokeh.models import Span, BoxAnnotation
from bokeh.io import curdoc
from bokeh.layouts import column, row
from bokeh.models.widgets import Button

def addAnnotations():
    span = Span(location=3, dimension='width',
              line_color='red', line_dash='dashed',
              line_width=1.5)
    box = BoxAnnotation(top=5, bottom=2, fill_alpha=0.1, fill_color='green')
              
    fig.add_layout(span)
    fig.add_layout(box)

fig = Figure(width=1000, height=500)
cir = fig.circle(x=[1, 2, 3], y=[3, 4, 5])

button = Button(label='Add Annotation', width=300)
button.on_click(addAnnotations)


layout = column(row(button),row(fig))

curdoc().add_root(layout)
@bryevdv
Copy link
Member

bryevdv commented Apr 23, 2019

definitely a bug @smamyris thanks for the detailed report

cc @mattpap any thoughts?

@smamyris
Copy link
Author

smamyris commented Apr 23, 2019

Thanks for looking into it.
As a workaround manipulating the renderers attribute directly triggers the update correctly.

@mattpap mattpap modified the milestones: 1.1.1, short-term Apr 29, 2019
@happydasch
Copy link

happydasch commented Jul 29, 2019

with bokeh 1.3.0, when adding Annotations (tried it with Label and Span) after the plot was shown, the Annotations do not show up. Workaround for me is to remove the plot from layout and then add it again or to extend the renderers: plot.renderers.extend([span, label])

@p-himik
Copy link
Contributor

p-himik commented Mar 15, 2020

An alternative, more lightweight, workaround:

plot.js_on_change('center', CustomJS(args=dict(plot=plot),
                                     code="plot.properties.renderers.change.emit()"))

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

Successfully merging a pull request may close this issue.

5 participants