Skip to content

Instantly share code, notes, and snippets.

@nicain
Last active June 14, 2017 23:10
Show Gist options
  • Save nicain/bb7f16ee7b8d1e479e39f6bac3bcd423 to your computer and use it in GitHub Desktop.
Save nicain/bb7f16ee7b8d1e479e39f6bac3bcd423 to your computer and use it in GitHub Desktop.
from bokeh.models.widgets import Button, Dropdown
from bokeh.layouts import column, widgetbox, row
from bokeh.io import show, curdoc, output_notebook
from bokeh.application.handlers import FunctionHandler
from bokeh.application import Application
def modify_doc(doc):
# This works with Bokeh server and jupyter:
main_button = Button(label='Refresh')
# This only works in Bokeh server:
# main_button = Dropdown(label='Refresh', menu=[('A', 'A'), ('B', 'B')])
layout = column([main_button], height=200)
def create_button(label):
return Button(label=str(label))
# Update the plot
def update(*args):
layout.children = layout.children + [create_button(len(layout.children))]
main_button.on_click(update)
doc.add_root(layout)
doc.title = "Example"
run_mode = 'bokeh_server'
if run_mode == 'bokeh_server':
# bokeh server:
modify_doc(curdoc())
elif run_mode == 'jupyter_notebook':
# jupyter notebook cell:
output_notebook()
handler = FunctionHandler(modify_doc)
app = Application(handler)
doc = app.create_document()
show(app, notebook_url="localhost:8888")
else:
raise NotImplementedError
@nicain
Copy link
Author

nicain commented Jun 14, 2017

Works in Chrome 58

@nicain
Copy link
Author

nicain commented Jun 14, 2017

Still Does not work on a fully up-to-date Firefox 54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment