I am programming a Bokeh application and trying to implement a select widget. Before I had my whole plot with glyph etc. in one function and used this function as the callback function for my select widget and everything worked fine. But the performance was pretty bad. So, I tried to make the plot outside of a function and then the callback functions separately. Now the select widget does not work properly anymore. I do not get any error when starting the application (I use the Bokeh serve --show main.py method). The select widget shall change the values of the y-axis and update the y-axis label at the same time. The label gets updated but the values are not changing. My code looks like this:
sel_yaxis = Select(
title='Select Y Axis',
options=sorted(head_columns.keys()),
value='Demonstrative word'
)
def set_axis(attr, old, new):
# Save value for y-axis from select input widget within the "top" variable
# in the glyph. It will automatically update on changing the select widget within the application.
y_axis = head_columns[sel_yaxis.value]
# Set the label on y-axis so that the glyph displayed and y-axis label match
p.yaxis.axis_label = sel_yaxis.value
c.yaxis.axis_label = sel_yaxis.value
sel_yaxis.on_change('value', set_axis)
p = figure(
title='',
plot_width=1000,
plot_height=700,
x_axis_label='ID',
toolbar_location='above',
tools='pan, box_select, save, undo, redo, xwheel_zoom, reset'
)
c = figure(
title='',
plot_width=1000,
plot_height=700,
x_axis_label='ID',
toolbar_location='above',
tools='pan, box_select, save, undo, redo, xwheel_zoom, reset'
)
# Holds the x-axis ID values for the glyph
id = head_columns['id']
p.yaxis.axis_label = sel_yaxis.value
c.yaxis.axis_label = sel_yaxis.value
# Render glyph into plot
p.vbar(
x=id,
top=y_axis,
source=source,
width=0.8,
line_alpha=0.3,
)
c.scatter(
x=id,
y=y_axis,
source=source
)
The same way it was working good within one main function to create the plot.
Any ideas?
Regards