Select widget does not update plot

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

Hi @timmyaof I have the same response I had on Stack Overflow: It’s not clear either your expectations, or what is actually occurring, and absent a complete script to test its also not really possible to say if the code as given is behaving as expected. I encourage you to supply a complete, minimal, reproducer which is always, 100% the best way to help other people help you. If you can’t share actual data, make some fake data up for purposes of demonstration.

Otherwise, the only comments I can make just by looking at the code above is: All that callback does is change the axis title. If it the axis title is changing, it is working exactly as expected. If not, then a complete example is defintitely needed for inspection. If you are expecting more to happen, e.g. for some data to be updated, then your callback needs to actually do that work to make that happen. There are lots of short Bokeh server app examples in the repo that update data sources based on widgets that you can study and emulate:

Looks for lines that assign to source.data. That action is what updates the data for the glyphs that causes the plot to change.