Search code examples
pythonbokehtornadoattributeerror

How to run Bokeh app in Jupyter notebook?


I'd like to create and run bokeh application in Jupyter notebook. To try it I downloaded code from bokeh tutorial

from bokeh.io import output_notebook, show
output_notebook()
from bokeh.layouts import column
from bokeh.models import TextInput, Button, Paragraph

def modify_doc(doc):

    # create some widgets
    button = Button(label="Say HI")
    input = TextInput(value="Bokeh")
    output = Paragraph()

    # add a callback to a widget
    def update():
        output.text = "Hello, " + input.value
    button.on_click(update)

    # create a layout for everything
    layout = column(button, input, output)

    # add the layout to curdoc
    doc.add_root(layout)

# In the notebook, just pass the function that defines the app to show
# You may need to supply notebook_url, e.g notebook_url="http://localhost:8889" 
show(modify_doc, notebook_url="http://localhost:8888") 

When I run it in Jupyter notebook, I get error message below:

ERROR:tornado.application:Uncaught exception in /ws Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\websocket.py", line 494, in _run_callback result = callback(*args, **kwargs) File "C:\Users\123058850\AppData\Roaming\Python\Python36\site-packages\bokeh\server\views\ws.py", line 121, in open if self.selected_subprotocol != 'bokeh': AttributeError: 'WSHandler' object has no attribute 'selected_subprotocol'

Can you please help me understand what is wrong?


Solution

  • If seems like in your environment, you have some old Tornado version installed somehow. tornado.websocket.WebSocketHandler.selected_subprotocol has appeared in Tornado 5.1.