Skip to content Skip to sidebar Skip to footer

Python Bokeh Add An Alert Based On A Python Object

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 so

Solution 1:

In your code you were mixing JS callback with Python callback. You cannot pass CustomJS callback to Python callback. See corrected code below. If you want to run it as server app just comment show(layout) and uncomment the other two lines at the bottom and run it with bokeh serve --show myapp.py. Code works for Bokeh v2.1.1

from bokeh.io import curdoc, show
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")
button_group = RadioButtonGroup(labels=['Alert ON', 'Alert OFF'], active=0)

code = 'if (button_group.active == 0) { alert("ALERT !"); }'
button_classify.js_on_click(CustomJS(args={'button_group': button_group}, code=code))
layout = column(button_group, button_classify)

show(layout)

# curdoc().add_root(layout)
# curdoc().title = "Pop-up Alert"

Post a Comment for "Python Bokeh Add An Alert Based On A Python Object"