Last active
June 14, 2017 23:10
-
-
Save nicain/bb7f16ee7b8d1e479e39f6bac3bcd423 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Still Does not work on a fully up-to-date Firefox 54