Hello,
My glyph labels are not updating as I expected. Could someone tell me what I’m missing?
Info:
- Bokeh 0.12.13
- Pandas 0.22.0
- Spyder 3.2.6
- Anaconda 1.6.11
- Firefox Quantum 58.0.1 (64-bit)
Screenshots:
The chart starts out looking fine:
But when I change the value, the label stays in the same position (I expected it to be at the end of the bar), and the text of the label does not change (I expected it to be 2).
I also get a browser error when changing the value to two. I cannot tell why I’m getting this error, as I have printed values and everything looks good to me:
Error: attempted to retrieve property array for nonexistent field ‘one’
Code:
import pandas as pd
from bokeh.layouts import row, widgetbox
from bokeh.models.widgets import Select
from bokeh.plotting import curdoc, figure
from bokeh.models import ColumnDataSource, LabelSet
from bokeh.models.ranges import FactorRange
df = pd.DataFrame(data={
‘category’: [‘a’],
‘one’: [1],
‘two’: [2],
})
source = ColumnDataSource(df)
p = figure(plot_width=800, plot_height=175, title=‘test’,
y_range=FactorRange(factors=list(source.data[‘category’])),
)
h1 = p.hbar(right=‘one’, y=‘category’, color=‘darkgrey’,
height=0.8, source=source)
labels = LabelSet(
text=‘one’, x=‘one’, y=‘category’,
text_font_size=‘9pt’, level=‘glyph’,
x_offset=3, y_offset=-6.5, source=source)
p.add_layout(labels)
def update_source():
df2 = df.reindex(columns=[‘category’, nums.value, ])
source.data = source.from_df(df2)
def update_glyph():
h1.glyph.right = nums.value
labels.text = nums.value
labels.x = nums.value
def update(attr, old, new):
update_source()
update_glyph()
nums = Select(title=‘Value’, value=‘one’, options=[‘one’, ‘two’])
nums.on_change(‘value’, update)
w = widgetbox([nums])
r = row([w, p], sizing_mode=“scale_width”)
curdoc().add_root(r)
curdoc().title = “test”
``
Many thanks!