I'm doing a Bokeh page were I do some calculations in Python, sometimes the calculations crashes and I want to use the "Alert" browser popup to let the user know that they added some bad data. I used this example and added a Radiobuttongroup where I only want to Alert the user if the RadioButton is set to Make alert
. (I'm looking for a general "python solution").
from bokeh.io import curdoc
from bokeh.models.widgets import Button, RadioButtonGroup
from bokeh.layouts import column
from bokeh.models.callbacks import CustomJS
button_classify = Button(label="Create Pop-up alert")
callback = CustomJS(args={}, code='alert("hello!");')
callback2 = CustomJS(args={}, code='')
button_group = RadioButtonGroup(labels=['Make alert', 'Dont make an alert'],
active=0)
def determine_button() -> CustomJS:
if button_group.active == 0:
return callback
else:
return callback2
button_classify.js_on_click(determine_button)
layout = column(button_group,
button_classify)
curdoc().add_root(layout)
curdoc().title = "Pop-up Alert"