Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding objects dynamically in bokeh server application

I would like to add objects dynamically on the bokeh server. The example I am trying to run is the following bokeh server app:

from bokeh.layouts import column
from bokeh.plotting import curdoc
from bokeh.models import Button

def add_button():
    print("adding button")
    curdoc().add_root(column(button, button2))


 button = Button(label="Start", button_type="success")
 button.on_click(add_button)
 button2 = Button(label="Next", button_type="success")

 curdoc().add_root(column(button))

Many thanks for any help.

like image 617
Karel Macek Avatar asked Apr 16 '26 18:04

Karel Macek


1 Answers

Did you want to keep adding a new button each time? if so try this :

from bokeh.layouts import column, layout
from bokeh.plotting import curdoc
from bokeh.models import Button
from bokeh.models.widgets import Div


def add_button():
    print("adding button")
    layout.children.append(Button(label="Hi I am another button", button_type="success"))


button = Button(label="Click to add a button", button_type="success")
button.on_click(add_button)
layout = layout([[button]])
curdoc().add_root(layout)

If you only wanted to add a new button once, then just append Button2.

like image 162
Anthonydouc Avatar answered Apr 19 '26 08:04

Anthonydouc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!