Bokeh offers the .visible = False functionality to hide a button. However this essentially means that the button is removed from the layout which triggers the compute layout function.
In my case I’d like to keep the layout but instead display the background at the same position. Is there an easy way to achieve this?
Well, Bokeh 3.0 is moving away from managing layout directly so perhaps it will be a more feasible option once it is released. cc @mateusz I don’t have any other suggestions presently, however.
If the efficiency of computing the layout is a concern, I cannot offer a workaround unfortunately.
However, if you are concerned only with preserving the placement of objects on the page, you could have the button and a spacer share the same real-estate by making their visible properties the negation of one another. (I have used similar logic to achieve dynamic layouts in prior bokeh apps and the time involved in re-layout was generally acceptable for my cases.)
I had issues with complex layouts with many plots a few years ago in scenarios where I did not expect redraw operations to occur.
See my following discourse topic and the solution I implemented to workaround it as the last post in the thread. No guarantee it will address your particular use-case, but it is at least passingly relevant.