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 |
Works in Chrome 58
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
When this code is run in bokeh server, both main_button=Button and main_button=Dropdown work. When the code is copied into a jupyter notebook cell and evaluated (and the run_mode is changed), only main_button=Button (main_button=Downdown)
bokeh (0.12.6)
jupyter (1.0.0)
jupyter-client (5.0.1)
jupyter-console (5.1.0)
jupyter-core (4.3.0)
notebook (5.0.0)
firefox (52.0 64-bit)