☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Bokeh app does not display in jupyter notebook using python 3.8.3 -- is this a bug?

Community Supportserver
Ricyteach
Ricyteach

Hello, I didn’t want to post this on the bugs page yet in case I am doing something incorrect.

The following code * works perfectly in a Jup notebook in a fresh python 3.7.3 venv, but the app does not display using identical code and python 3.8.3. Am I doing something wrong or should I open an issue?

This is just a regular venv with notebook and bokeh installed using pip (not conda or something else).

from bokeh.io import output_notebook, show
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, HoverTool
import pandas as pd 
import numpy as np
from bokeh.layouts import grid
from bokeh.models import Button, TextInput


output_notebook()

sample1 = np.random.multivariate_normal([0,0], [[1,0],[0,1]], 100)
sample2 = np.random.multivariate_normal([1,1], [[0.05,0],[0,0.05]], 100)
sample = np.concatenate([sample1, sample2])

df = pd.DataFrame(sample, columns=('x','y'))
df['value'] = np.sqrt(df['x']**2 + df['y']**2)
df.head()

source = ColumnDataSource(df)
tools = "box_zoom, undo, crosshair"

def modify_doc(doc):
    # same as before
    source = ColumnDataSource(df)
    p = figure(tools=tools)
    p.scatter('x','y', source=source, alpha=0.5)
    p.add_tools(
        HoverTool(
            tooltips=[('value','@value{2.2f}'), 
                      ('index', '@index')]
        )
    )
    
    # this function is called when the button is clicked
    def update():
        # number of points to be added, taken from input text box
        n = int(npoints.value)
        # new sample of points to be added. 
        # we use the a narrow gaussian centred on (-1, 1), 
        # and draw the requested number of points
        sample3 = np.random.multivariate_normal([-1,-1], [[0.05,0],[0,0.05]], n)
        df_new = pd.DataFrame(sample3, columns=('x','y'))
        df_new['value'] = np.sqrt(df['x']**2 + df['y']**2)
        # only the new data is streamed to the bokeh server, 
        # which is an efficient way to proceed
        source.stream(df_new)
    
    # GUI: 
    button = Button(label='add points:')
    npoints = TextInput(value="50")
    button.on_click(update)
    # arranging the GUI and the plot. 
    layout = grid([[button, npoints], p])
    doc.add_root(layout)

show(modify_doc)

* Codes comes from this tutorial: Interactive Visualization with Bokeh

⌁   Link to post
Ricyteach
Ricyteach

I did not check the console last night when I posted, but now the problem has gone from constant to intermittent.

I have also tried in 3.8.1, but cannot reproduce the problem. So far seems like it only happens 3.8.3 but so far I’ve only tried 3.8.1 and 3.7.3.

There are lots of messages in the console. I don’t know if will be helpful to just copy and paste the console log? Here it is:

menubar.js:263 actions jupyter-notebook:find-and-replace does not exist, still binding it in case it will be defined later...
MenuBar.bind_events @ menubar.js:263
bidi.js:19 Loaded moment locale en
extension.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
main.js:237 Widgets are not available.  Please install widgetsnbextension or ipywidgets 4.0
(anonymous) @ main.js:237
VM375 bokeh-2.0.2.min.js:238 [bokeh] setting log level to: 'info'
:44599/autoload.js?bokeh-autoload-element=1003&bokeh-absolute-url=http://localhost:44599&resources=none:1 Failed to load resource: net::ERR_CONNECTION_RESET
session.js:54 Session: kernel_created (1b7b38c0-73c5-437f-bf24-d6ebeb19009b)
kernel.js:462 Starting WebSockets: ws://localhost:8888/api/kernels/b8faffab-f213-464b-ad25-efbd08010e91
kernel.js:106 Kernel: kernel_connected (b8faffab-f213-464b-ad25-efbd08010e91)
kernel.js:106 Kernel: kernel_ready (b8faffab-f213-464b-ad25-efbd08010e91)
VM375 bokeh-2.0.2.min.js:238 [bokeh] setting log level to: 'info'
kernel.js:1008 Couldn't process kernel message TypeError: Cannot read property 'trim' of undefined
    at output (eval at append_javascript (outputarea.js:763), <anonymous>:47:39)
    at Kernel._handle_output_message (kernel.js:1197)
    at proxy (jquery.min.js:10502)
    at Kernel._handle_iopub_message (kernel.js:1224)
    at Kernel._finish_ws_message (kernel.js:1016)
    at kernel.js:1007
(anonymous) @ kernel.js:1008
Promise.catch (async)
Kernel._handle_ws_message @ kernel.js:1008
proxy @ jquery.min.js:10502
VM385:12 GET http://localhost:35717/autoload.js?bokeh-autoload-element=1003&bokeh-absolute-url=http://localhost:35717&resources=none net::ERR_CONNECTION_REFUSED
(anonymous) @ VM385:12
handleAddOutput @ VM370:86
dispatch @ jquery.min.js:5237
elemData.handle @ jquery.min.js:5044
trigger @ jquery.min.js:8471
(anonymous) @ jquery.min.js:8549
each @ jquery.min.js:367
each @ jquery.min.js:202
trigger @ jquery.min.js:8548
events.trigger @ events.js:31
OutputArea.append_output @ outputarea.js:355
OutputArea.handle_output @ outputarea.js:257
output @ codecell.js:395
Kernel._handle_output_message @ kernel.js:1197
proxy @ jquery.min.js:10502
Kernel._handle_iopub_message @ kernel.js:1224
Kernel._finish_ws_message @ kernel.js:1016
(anonymous) @ kernel.js:1007
Promise.then (async)
Kernel._handle_ws_message @ kernel.js:1007
proxy @ jquery.min.js:10502
⌁   Link to post
Bryan
Bryan

@Ricyteach is your notebook running at a different url than the default localhost:8888? If so, you will have to supply the notebook_url parameter to show. I wish this was not the case, but the Jupyter team refuse to expose the front-end URL to the python kernel, as a matter of principle, so there is nothing we can do about that.

⌁   Link to post
Ricyteach
Ricyteach

Yes, locally running. Clean virtualenv.

Again to be clear: the problems seems to be intermittent now. I don’t know how to consistently reproduce it. But the failure to run definitely happens most of the time.

I’m wondering now if part of the problem is that I should install all of jupyter rather than just pip install notebook. But installing all of jupyter takes FOREVER.

⌁   Link to post
Ricyteach
Ricyteach

Here’s another console log if it helps:

kernel.js:1008 Couldn't process kernel message TypeError: Cannot read property 'trim' of undefined
    at output (eval at append_javascript (outputarea.js:763), <anonymous>:47:39)
    at Kernel._handle_output_message (kernel.js:1197)
    at proxy (jquery.min.js:10502)
    at Kernel._handle_iopub_message (kernel.js:1224)
    at Kernel._finish_ws_message (kernel.js:1016)
    at kernel.js:1007
(anonymous) @ kernel.js:1008
Promise.catch (async)
Kernel._handle_ws_message @ kernel.js:1008
proxy @ jquery.min.js:10502
VM134:12 GET http://localhost:36711/autoload.js?bokeh-autoload-element=1091&bokeh-absolute-url=http://localhost:36711&resources=none net::ERR_CONNECTION_REFUSED
(anonymous) @ VM134:12
handleAddOutput @ VM109:86
dispatch @ jquery.min.js:5237
elemData.handle @ jquery.min.js:5044
trigger @ jquery.min.js:8471
(anonymous) @ jquery.min.js:8549
each @ jquery.min.js:367
each @ jquery.min.js:202
trigger @ jquery.min.js:8548
events.trigger @ events.js:31
OutputArea.append_output @ outputarea.js:355
OutputArea.handle_output @ outputarea.js:257
output @ codecell.js:395
Kernel._handle_output_message @ kernel.js:1197
proxy @ jquery.min.js:10502
Kernel._handle_iopub_message @ kernel.js:1224
Kernel._finish_ws_message @ kernel.js:1016
(anonymous) @ kernel.js:1007
Promise.then (async)
Kernel._handle_ws_message @ kernel.js:1007
proxy @ jquery.min.js:10502
VM115 bokeh-2.0.2.min.js:238 [bokeh] setting log level to: 'info'
⌁   Link to post
Ricyteach
Ricyteach

And here is a log from a time when it was successful:

kernel.js:1008 Couldn't process kernel message TypeError: Cannot read property 'trim' of undefined
    at output (eval at append_javascript (outputarea.js:763), <anonymous>:47:39)
    at Kernel._handle_output_message (kernel.js:1197)
    at proxy (jquery.min.js:10502)
    at Kernel._handle_iopub_message (kernel.js:1224)
    at Kernel._finish_ws_message (kernel.js:1016)
    at kernel.js:1007
(anonymous) @ kernel.js:1008
Promise.catch (async)
Kernel._handle_ws_message @ kernel.js:1008
proxy @ jquery.min.js:10502
VM115 bokeh-2.0.2.min.js:238 [bokeh] setting log level to: 'info'
VM115 bokeh-2.0.2.min.js:551 [bokeh] Websocket connection 1 is now open
VM115 bokeh-2.0.2.min.js:162 [bokeh] document idle at 141 ms
VM115 bokeh-2.0.2.min.js:160 Bokeh items were rendered successfully
⌁   Link to post
Ricyteach
Ricyteach

Good question, and apologies for the unnecessarily complicated example.

No, it happens with any notebook when attempting to use the pattern:

def myapp(doc): ...

show(myapp)

It does NOT happen when you do something like:

p = figure()
show(p)
⌁   Link to post
Ricyteach
Ricyteach

Had a busy week; finally confirmed this problem does not occur- never happens- using the Python installation on my Windows machine at work, nor does it occur on the Debian WSL on the same machine.

However, it is back to occurring 100% of the time on my Chromebook, and I have now replicated it in Linux on two different Chromebooks, both of them Acers running ChromeOS v. 83 (but different models), and it occurs using both Python 3.7.3 and 3.8.3.

⌁   Link to post
Bryan
Bryan

I have not been able to find any concrete information. There are various allusions to ChromeOS being configured in some way by default to to like connections to localhost, e.g.

You might try loading the autoload URL from the console log directly in a URL bar, seeing if there are any relevant settings (e.g. maybe something mentioned in that SO post above), or (if possible?) try other browsers on the Chromebook. Unfortunately I do not have access to any Chromebook to experiment.

⌁   Link to post
Ricyteach
Ricyteach

hmmm I’m far less knowledgeable than you I am certain but I’m unsure if that is helpful since the browser is able to read localhost:8888 just fine, based on the fact that is where the notebook is being served from. And as shown in the example code, the output_notebook() function is being run so the bokeh app should appear inside the notebook.

I will look into trying an alternative browser.

I could also try setting up a remote notebook server and seeing if the problem persists for a remote client. But I am not sure how to set that up.

⌁   Link to post
Bryan
Bryan

I’m just grasping as straws, really. The relevant, important line in the console log is this:

VM134:12 GET http://localhost:36711/autoload.js?bokeh-autoload-element=1091&bokeh-absolute-url=http://localhost:36711&resources=none net::ERR_CONNECTION_REFUSED

When you show a Bokeh app in a notebook, Bokeh installs URL handlers for routes like the one above on the notebook’s Tornado IOLoop. Then the Jupyter Kernel makes an HTTP request to those URLs to connect and display the app in an output cell. Something on your system is blocking that HTTP request from succeeding, but I am afraid I don’t have any clear idea what.

⌁   Link to post
Ricyteach
Ricyteach

Konquerer install finished faster than I thought it would-- and everything works perfectly in there! Very very odd. So I guess this means it is something going on in the Chrome 83.

My Chrome just pinged me to install an update; I’m going to try installing it and seeing what happens. EDIT: nope, no help there. EDIT: worth noting the same versions of the Chrome browser (down to the smallest subversion number) are now reported to be installed on the Windows machine and the Chromebooks.

⌁   Link to post
Bryan
Bryan

Sure, but I should be up front and state realistically that if there is an issue somehow tied to specific hardware then there may nothing we can do.

Can you successfully load the failing URL from the console log manually?

⌁   Link to post
Ricyteach
Ricyteach

I understand. SinceI have replicated it on two different models of Acer Chromebook I doubt it is hardware specific-- they are very different hardware (manufactured a couple years apart). Am working on replicating it on another brand to confirm it is all Chromebooks.

⌁   Link to post
Ricyteach
Ricyteach

Correct, that seems to be the case. I’ll just point out that Chromebooks are a very widely used platform and getting more use every day. They are pretty much all I do this kind of work on anymore (though I’m far from a professional developer).

I pasted the URL below into the omnibar and it loads what looks like a javascript file just fine.

http://localhost:43899/autoload.js?bokeh-autoload-element=1003&bokeh-absolute-url=http://localhost:43899&resources=none

⌁   Link to post
Ricyteach
Ricyteach

AH HA! A new clue: when I navigate to that URL in a separate tab and come back to the notebook, this appears below the cell that is not rendering the Bokeh app correctly:

WARNING:tornado.access:404 GET /favicon.ico (::1) 1.97ms

EDIT: This SO question seems to be related to this but I have no idea how to fix it. EDIT: I guess this message could be unrelated to my problem though-- maybe the error is related to the other tab not having a favicon at the top *shrug*.

⌁   Link to post
Bryan
Bryan

The favicon message is harmless. Bokeh server doesn’t currently have any support to provide favicons, but that’s nothing that will stop an app from rendering (and is commonly seen in both wrt to Bokeh and in general). The issue is truly (and specifically) the ERR_CONNECTION_REFUSED on the autoload URL.

If you paste the URL in the navbar and repeatedly force reload does it always load, or does ever fail intermittently? If it always succeeds then perhaps there is a race condition and the connection is refused because the endpoint serving the URL is not running yet. But I don’t know why that would only be the case on Chrome on ChromeOS.

⌁   Link to post
Ricyteach
Ricyteach

I think you have figured it out— yes, if I run all the cells the output does not initially appear and the error occurs. However, if I right click on the notebook GUI and select “reload frame”, everything works. So it must be asking for that URL before it is available…?

⌁   Link to post
Bryan
Bryan

What happens if you run this code manually right after a failure?

from bokeh.io.notebook import run_notebook_hook
from bokeh.io.state import curstate

notebook_url = "localhost:8888" # or whatever it really is

run_notebook_hook('jupyter', 'app', myapp, curstate(), notebook_url)

Edit: missed your earlier reply. Seems plausible, I think trying the above experiment is also still valuable

⌁   Link to post
Bryan
Bryan

Oh, right. It’s still generating a new random port downstream from that call. I’ll have to try and construct a test that hits the existing port, but it may it may have to involve you editing the installed Bokeh source.

⌁   Link to post
Ricyteach
Ricyteach
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-5-35d7c2d71572> in <module>
      4 notebook_url = "localhost:8888" # or whatever it really is
      5 
----> 6 run_notebook_hook('jupyter', 'app', bkapp, curstate(), notebook_url, port=45237)

~/venvs/dxf-test/lib/python3.7/site-packages/bokeh/io/notebook.py in run_notebook_hook(notebook_type, action, *args, **kw)
    296     if _HOOKS[notebook_type][action] is None:
    297         raise RuntimeError("notebook hook for %r did not install %r action" % notebook_type, action)
--> 298     return _HOOKS[notebook_type][action](*args, **kw)
    299 
    300 #-----------------------------------------------------------------------------

~/venvs/dxf-test/lib/python3.7/site-packages/bokeh/io/notebook.py in show_app(app, state, notebook_url, port, **kw)
    472         origin = _origin_url(notebook_url)
    473 
--> 474     server = Server({"/": app}, io_loop=loop, port=port,  allow_websocket_origin=[origin], **kw)
    475 
    476     server_id = uuid4().hex

~/venvs/dxf-test/lib/python3.7/site-packages/bokeh/server/server.py in __init__(self, applications, io_loop, http_server_kwargs, **kwargs)
    393             http_server_kwargs['ssl_options'] = context
    394 
--> 395         sockets, self._port = bind_sockets(opts.address, opts.port)
    396         self._address = opts.address
    397 

~/venvs/dxf-test/lib/python3.7/site-packages/bokeh/server/util.py in bind_sockets(address, port)
     58 
     59     '''
---> 60     ss = netutil.bind_sockets(port=port or 0, address=address)
     61     assert len(ss)
     62     ports = {s.getsockname()[1] for s in ss}

~/venvs/dxf-test/lib/python3.7/site-packages/tornado/netutil.py in bind_sockets(port, address, family, backlog, flags, reuse_port)
    172 
    173         sock.setblocking(False)
--> 174         sock.bind(sockaddr)
    175         bound_port = sock.getsockname()[1]
    176         sock.listen(backlog)

OSError: [Errno 98] Address already in use
⌁   Link to post
Ricyteach
Ricyteach

And here is the console error that happens at the same time, if it’s of any use:

Couldn't process kernel message TypeError: Cannot read property 'trim' of undefined
    at output (eval at append_javascript (outputarea.js:763), <anonymous>:47:39)
    at Kernel._handle_output_message (kernel.js:1197)
    at proxy (jquery.min.js:10502)
    at Kernel._handle_iopub_message (kernel.js:1224)
    at Kernel._finish_ws_message (kernel.js:1016)
    at kernel.js:1007
(anonymous) @ kernel.js:1008
Promise.catch (async)
Kernel._handle_ws_message @ kernel.js:1008
proxy @ jquery.min.js:10502
⌁   Link to post
Bryan
Bryan

The trim message is not coming from Bokeh, I’m not sure what it is but it seems common with the notebook in general. (Note that it shows up even in the working cases)

What I am trying to test is whether the the app can be displayed if some delay is added. Unfortunately the simple routes I thought of also try to do all the server setup again, as seen above, so that’s not helpful (because it will fail with “address already in use”, etc). I think testing this will be a bit more involved. I will have to look in to getting you some detailed instructions, but it probably won’t be today. In the mean time, a GH issue is probably the best place to move to.

⌁   Link to post

End of archived discussion · Replies are disabled