Adding widget dynamically breaks layout

I need to add data filters dynamically in bokeh, i.e. every time a button is pressed, a new filter is appended to a list of data filters.
However, the layout gets broken after
a new widget is added: new ones get written over(or under) old ones instead of the layout being recomputed.
Seems to happen because the original height of the container (e.g. 0 px) is kept for the div even after new element is inserted.
Code example

from bokeh.layouts import row, column
from bokeh.models.widgets import Button, Select
from bokeh.io import curdoc

def add_select():
feature = Select(value=‘feat’, options=[“a”, “b”])
dynamic_col.children.append(feature)

b1 = Button(label=“Add condition”, button_type=“success”)
b1.on_click(add_select)

b2 = Button(label=“Apply”, button_type=“success”)

dynamic_col = column()
curdoc().add_root(column(b1, dynamic_col, b2))

Layout before click

Layout after Select is added

How to resolve this issue? Bokeh version ‘0.12.13’

The answer to this question can be found here:

1 Like

@Tommy_Carstensen Thanks for the link back to SO, but FYI with recent versions of Bokeh (e.g. 2.2.1) the original code node works correctly as-is. That said, I do agree that keeping layouts as absolutely simple as possible is always good guidance.

1 Like