4

I want to add filters dynamically in bokeh, i.e. every time a button is pressed, a new filter is appended. However, the layout gets broken after a new widgets are added: new ones get written over old ones instead of the layout being recomputed. 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"])
    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 clicking "Add" button

Layout before clicking "Add" button

Layout after Select widget gets added

Layout after Select widget gets added

1
  • With recent versions of Bokeh (e.g. 2.2.1) the original code node works correctly as-is. Commented Sep 23, 2020 at 0:46

1 Answer 1

4

Why don't you use a single list to handle all your widgets ?

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

def add_select():
    feature = Select(value='feat', options=["a"])
    dynamic_col.children.insert(-1, feature)

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

b2 = Button(label="Apply", button_type="success")

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

I "insert" instead of "append" the widget to let the 2nd button at the end of the list

I got this result :

result

Sign up to request clarification or add additional context in comments.

1 Comment

FYI with recent versions of Bokeh (e.g. 2.2.1) the original code node works correctly as-is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.