It works good when you click the 1st button (1d-factors) and then the 2nd one (2d-factors), but if you click on the 1st button again, you’ll see that y-ticks dissappeared and in console.log there error “TypeError: t is undefined” will appear, on the next iteration you’ll see an additional error.
This can be seen here - https://gifyu.com/image/dJuG.
Replace lines like fig.x_range.factors = new FactorRange(...); with fix.x_range = new FactorRange(...).
Well, the exception is gone with that change, but now the plot is just empty, except for the top left corner. Judging by the Bokeh code, it doesn’t want you to change the ranges at all. You might as well recreate the whole plot then.
Maybe it would be cheaper to have 2 completely overlapped figures (one with 1d-range and the 2nd with 2d-range) and hide/show them when it’s neccessary.