Hiding a button without removing it from layout

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?

You best bet is probably to disable the button instead. There is no way to remove it without a re-layout.

Unfortunately the disabled button is not an option for me as this functionality is already reserved for actually triggering the button.

I’d like to mention that in HTML both functionality exist.

visibility="hidden"

(what I need)

display="none"

(what is currently supported, representing visibility=False)

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.

1 Like

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.)

1 Like

Layout computing is my only concern unfortunately (complex layout with many plots).

For consistent placements I have already played around with empty divs which works fine and is similar to your proposal.

I see.

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.

1 Like