Update categorical y_range after callback

I’m using Bokeh server and one of the plots I’m generating has a categorical y_range.
Using a Select widget to select what data is displayed.

When changing the SELECT to trigger a callback and update the CDS.data.update() my graph content updates but the categorical y_range does not update. It doesn’t seem that auto-ranging exists in categorical ranges. Is there another option to dynamically update the axis.

I think using factors should work in this case. Initially define y_range as empty list in the figure. Then while callback updates the data for the plot, update the y_range.factors with the new y_axis values, passed as a list.


plot_name = figure(title="Plot", plot_height=600, plot_width=800, y_range=[])

# When the plot data gets updated in the callback, use this to update the 
plot_name.y_range.factors = list(categories_names)

It doesn’t seem that auto-ranging exists in categorical ranges.

It doesn’t, and the reason for this is that categorical factors do not have any inherent ordering. Bokeh can’t know in what order to display factors on the axis, except that you tell it, explicitly, by providing a list.

It’s possible we could think about adding a FactorDataRange but it would need to have a mandatory CustomJS-type property that users supply, that would perform an expected sorting, on whatever the list of factors ends up being. If you’d like to discuss the possibility (and especially if you are interested in collaborating to help make it happen) then it would be appropriate to open a GitHub issue.


This seemed to work. Although since y_range was not defined prior to the plot being generated it would be blank until I made a change in the selection. It then updated and would work. To get around this by default I would call the update after all the graphs were generated. So it was like the user basically made the same default starting selection and everything would show up.