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] Updating title object in bokeh server does not work #8865

Open
kasuteru opened this issue Apr 23, 2019 · 3 comments
Open

[BUG] Updating title object in bokeh server does not work #8865

kasuteru opened this issue Apr 23, 2019 · 3 comments

Comments

@kasuteru
Copy link

I am not able to change the title text of a figure interactively. In the minimal working example below, the title stays "old title" even after clicking the button. In the non-interactive version, this works fine.

Bokeh version 1.1.0.
Running on Windows 10, Anaconda environment, bokeh serve --show opens Firefox browser.


from bokeh.models.annotations import Title
from bokeh.plotting import figure, show
from bokeh.models.widgets import Button
from bokeh.layouts import row
import numpy as np
from bokeh.io import curdoc
x = np.arange(0, 2*np.pi, np.pi/100)
y = np.sin(x)
p = figure(title="old title")
p.circle(x, y)

button = Button(label="Update available curves", button_type="success")
def on_button():
  t = Title()
  t.text = 'new title'
  p.title = t
  print("Clicked")
button.on_click(on_button)

curdoc().add_root(row(p, button))

The title text stays the same. No error / warning shown in the console. "Clicked" is printed, so the function is definitely executed.

@bryevdv
Copy link
Member

bryevdv commented Apr 23, 2019

You should change the text on an existing title:

def on_button():
  p.title.text = 'new title'

The best practice and guidance in general for Bokeh is always: make the smallest change possible. In this specific case that means updating the text on the existing title, not replacing the Title object wholesale (which is a much more cumbersome operation). This principle is how things are demonstrated across the board in bokeh docs and examples.

cc @mattpap That said we should figure out things in this case (or make Title objects themselves readonly so that they can only be updated not replaced... I am somewhat inclined to do this in several places for the future)

@bryevdv bryevdv changed the title [BUG] Updating title text in bokeh server does not work [BUG] Updating title object in bokeh server does not work Apr 23, 2019
@kasuteru
Copy link
Author

Thanks for the quick response. I initially tried to change the title itself, not realizing it is an object with a "text" attribute. I then got the idea to change the whole object from a stackoverflow thread, where this was the accepted (but not most upvoted) answer... Your solution works for me.

@bryevdv
Copy link
Member

bryevdv commented Apr 23, 2019

@kasuteru if you have a link to the SO answer I can edit it

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

No branches or pull requests

2 participants