Repository: bokeh/bokeh

Issue:
Bokeh occasionally not working with Jupyter Notebook
I'm not sure what's going on. I get this error occasionally and I may have gotten a reproducible example but I haven't confirmed just yet.

There are no errors in the python side. Instead of a plot I see `<bokeh.io._CommsHandle at 0x109b1ec18>` as the output. The javascript console shows:

```
Kernel: kernel_restarting (b738e19a-021b-47ef-9d08-076f696147c8)
main.min.js:22329 Kernel: kernel_created (b738e19a-021b-47ef-9d08-076f696147c8)
main.min.js:22673 Starting WebSockets: ws://localhost:8888/api/kernels/b738e19a-021b-47ef-9d08-076f696147c8
main.min.js:22329 Kernel: kernel_connected (b738e19a-021b-47ef-9d08-076f696147c8)
main.min.js:22329 Kernel: kernel_ready (b738e19a-021b-47ef-9d08-076f696147c8)
(program):67 Bokeh: BokehJS loaded, going straight to plotting
cdn.pydata.org/bokeh/release/bokeh-0.11.0.min.js:3 Bokeh: setting log level to: 'info'
(program):53 Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.11.0.min.css
(program):55 Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.0.min.css
(program):72 Bokeh: BokehJS loaded, going straight to plotting

Could not open comm  --  Error: Class 1854dd25-3916-46bd-aab3-1729f21a403a not found in registry
main.min.js:23119 Couldn't process kernel message WrappedError(anonymous function) @ main.min.js:23119

Couldn't process kernel message WrappedError(anonymous function) @ main.min.js:23119
```



Discussion:
Since updating to Bokeh 11.0 I have not been able to render any plots or charts. Instead of showing the plots in the notebook, I get the output:

 < bokeh.io._CommsHandle at 0x0400c32d68 >

For me it does not crash the kernel.

Just to clarify, nothing crashes for me as well. Just not plots.

The new "comms handle" repr output is expected (but the plot should show up as well). Can you both report python, ipython versions, etc? It's possible that the new comms handle feature is tied more closely to specific ipython versions that was thought. 

python --version
Python 3.5.0

ipython --version
4.0.1

jupyter --version
4.0.6
pip freeze | grep notebook
notebook==4.1.0

pip freeze | grep jupyter
jupyter==1.0.0
jupyter-client==4.1.1
jupyter-console==4.0.3
jupyter-core==4.0.6

pip freeze | grep bokeh
bokeh==0.11.0

Chrome Version 47.0.2526.106 (64-bit)

I have same issue as @lindseydi. Have not gotten a plot to show up but does not crash the kernel.

Selected output from conda list:

anaconda                  2.4.1               np110py35_0    defaults
anaconda-client           1.2.1                    py35_0    defaults
bokeh                     0.11.0                   py35_1    defaults

ipykernel                 4.2.2                    py35_0    defaults
ipython                   4.0.2                    py35_0    defaults
ipython-genutils          0.1.0                     <pip>
ipython-notebook          4.0.4                    py35_3    defaults
ipython-qtconsole         4.0.1                    py35_4    defaults
ipython_genutils          0.1.0                    py35_0    defaults
ipywidgets                4.1.0                    py35_0    defaults

jupyter                   1.0.0                    py35_1    defaults
jupyter-client            4.1.1                     <pip>
jupyter-console           4.0.3                     <pip>
jupyter-core              4.0.6                     <pip>
jupyter_client            4.1.1                    py35_0    defaults
jupyter_console           4.0.3                    py35_0    defaults
jupyter_core              4.0.6                    py35_0    defaults

nbconvert                 4.1.0                    py35_0    defaults
nbformat                  4.0.1                    py35_0    defaults
notebook                  4.1.0                    py35_0    defaults
python                    3.5.1                         1    defaults

Can one or both of you post the notebooks somewhere so that we can investigate with them directly. 

Also are you trying a "run all"? Is there any difference if you execute cells individually one at a time?

@bryevdv no apparent difference between executing individually or "run all".

Here's the extent of a notebook that replicates my issue:

``` python
from bokeh.plotting import figure, output_file, show
from bokeh.io import output_notebook
output_notebook()
p = figure(title="Test", x_axis_label='x', y_axis_label='y')
p.line([1,2,3,4,5],[3,2,1,3,4])
show(p)
```

[bokeh_test.zip](https://github.com/bokeh/bokeh/files/99326/bokeh_test.zip)

Notebook file is attached.

OK, just as a quick smoke check, it works fine for me on OS X / Safari / Bokeh `master`

<img width="704" alt="screen shot 2016-01-21 at 9 14 36 am" src="https://cloud.githubusercontent.com/assets/1078448/12484335/7f804ef4-c01f-11e5-9e00-3a1df8f1a499.png">

It will take me somewhat longer to try and reproduce your environments exactly, it will probably be this weekend at least before I can make a stab at it. 

@PeterSulcs can you also attach the output of `conda list -e` that will make it easier for me to reproduce your environment exactly 

Also, what platform and browsers / browser versions?

Windows 7 64 bit
Google Chrome: Version 47.0.2526.111 m

```
λ conda list -e
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: win-64
_license=1.1=py35_1
alabaster=0.7.6=py35_0
anaconda=2.4.1=np110py35_0
anaconda-client=1.2.1=py35_0
argcomplete=1.0.0=py35_1
astropy=1.0.6=np110py35_0
babel=2.1.1=py35_0
backports_abc=0.4=py34_0
bcolz=0.9.0=np19py34_0
beautiful-soup=4.3.2=py34_1
beautifulsoup4=4.4.1=py35_0
binstar=0.11.0=py34_0
bitarray=0.8.1=py35_1
blaze=0.7.3=np19py34_0
blaze-core=0.8.3=py35_0
blist=1.3.6=py34_0
blz=0.6.2=np19py34_1
bokeh=0.11.0=py35_1
boto=2.38.0=py35_0
bottleneck=1.0.0=np110py35_0
bzip2=1.0.6=vc14_2
certifi=2015.9.6.2=py34_0
cffi=1.2.1=py35_0
clyent=1.2.0=py35_0
colorama=0.3.3=py35_0
comtypes=1.1.2=py35_0
configobj=5.0.6=py35_0
console_shortcut=0.1.1=py35_1
cryptography=1.0.2=py35_0
curl=7.45.0=vc14_0
cycler=0.9.0=py35_0
cython=0.23.4=py35_0
cytoolz=0.7.4=py35_0
datashape=0.4.7=np110py35_1
dateutil=2.1=py34_2
decorator=4.0.6=py35_0
docutils=0.12=py35_1
dynd-python=0.7.0=py35_0
fastcache=1.0.2=py35_0
flask=0.10.1=py35_1
freetype=2.5.5=vc14_0
future=0.13.1=py34_0
greenlet=0.4.9=py35_0
h5py=2.5.0=np110py35_4
hdf5=1.8.15.1=vc14_4
idna=2.0=py35_0
ipykernel=4.2.2=py35_0
ipython=4.0.2=py35_0
ipython-notebook=4.0.4=py35_3
ipython-qtconsole=4.0.1=py35_4
ipython_genutils=0.1.0=py35_0
ipywidgets=4.1.0=py35_0
itsdangerous=0.24=py35_0
jdcal=1.0=py35_0
jedi=0.9.0=py35_0
jinja2=2.8=py35_0
jpeg=8d=vc14_0
jsonschema=2.4.0=py35_0
jupyter=1.0.0=py35_1
jupyter_client=4.1.1=py35_0
jupyter_console=4.0.3=py35_0
jupyter_core=4.0.6=py35_0
launcher=1.0.0=4
libdynd=0.7.0=0
libpng=1.6.17=vc14_1
libpython=1.0=py34_1
libsodium=1.0.3=0
libtiff=4.0.6=vc14_1
llvmlite=0.8.0=py35_0
llvmpy=0.12.7=py34_0
lxml=3.4.4=py35_0
markupsafe=0.23=py35_0
matplotlib=1.5.0=np110py35_0
menuinst=1.3.1=py35_0
mingw=4.7=1
mistune=0.7.1=py35_0
mock=1.0.1=py34_0
msvc_runtime=1.0.1=vc14_0
multipledispatch=0.4.8=py35_0
nbconvert=4.1.0=py35_0
nbformat=4.0.1=py35_0
networkx=1.10=py35_0
nltk=3.1=py35_0
node-webkit=0.10.1=0
nose=1.3.7=py35_0
notebook=4.1.0=py35_0
numba=0.22.1=np110py35_0
numexpr=2.4.4=np110py35_0
numpy=1.10.1=py35_0
odo=0.3.4=py35_0
openpyxl=2.2.6=py35_0
openssl=1.0.2d=vc14_0
pandas=0.17.1=np110py35_0
path.py=8.1.2=py35_1
patsy=0.4.0=np110py35_0
pep8=1.6.2=py35_0
pickleshare=0.5=py35_0
pillow=3.0.0=py35_1
pip=7.1.2=py35_0
ply=3.8=py35_0
psutil=3.3.0=py35_0
py=1.4.30=py35_0
pyasn1=0.1.9=py35_0
pycosat=0.6.1=py35_0
pycparser=2.14=py35_0
pycrypto=2.6.1=py35_3
pycurl=7.19.5.1=py35_1
pyflakes=1.0.0=py35_0
pygments=2.0.2=py35_0
pymongo=2.8=py34_0
pyopenssl=0.15.1=py35_1
pyparsing=2.0.3=py35_0
pyqt=4.11.4=py35_4
pyreadline=2.1=py35_0
pytables=3.2.2=np110py35_1
pytest=2.8.1=py35_0
python=3.5.1=1
python-dateutil=2.4.2=py35_0
pytz=2015.7=py35_0
pywin32=219=py35_1
pyyaml=3.11=py35_2
pyzmq=15.2.0=py35_0
qt=4.8.7=vc14_5
qtconsole=4.1.1=py35_0
requests=2.9.1=py35_0
rope=0.9.4=py35_1
runipy=0.1.3=py34_0
scikit-image=0.11.3=np110py35_0
scikit-learn=0.17=np110py35_1
scipy=0.16.0=np110py35_0
seaborn=0.6.0=np19py34_0
setuptools=19.2=py35_0
simplegeneric=0.8.1=py35_0
sip=4.16.9=py35_2
six=1.10.0=py35_0
snowballstemmer=1.2.0=py35_0
sockjs-tornado=1.0.1=py35_0
sphinx=1.3.1=py35_0
sphinx_rtd_theme=0.1.7=py35_0
spyder=2.3.8=py35_0
spyder-app=2.3.8=py35_0
sqlalchemy=1.0.9=py35_0
statsmodels=0.6.1=np110py35_0
sympy=0.7.6.1=py35_0
tk=8.5.18=vc14_0
toolz=0.7.4=py35_0
tornado=4.3=py35_0
traitlets=4.0.0=py35_0
ujson=1.33=py35_0
unicodecsv=0.14.1=py35_0
werkzeug=0.11.2=py35_0
wheel=0.26.0=py35_1
xlrd=0.9.4=py35_0
xlsxwriter=0.7.7=py35_0
xlwings=0.5.0=py35_0
xlwt=1.0.0=py35_0
zeromq=4.1.3=vc14_1
zlib=1.2.8=vc14_2
```

I am having the same problem.  Here's our stack:
- Ipython notebooks running on windows server 2008.  
- About 5 users running notebooks on the server
- 0 to 10 notebooks running at a time (problem happens when 0 or many others running)
- Started happening just recently (with a recent packages update)
- happens with chrome and firefox client browsers
- Really weird thing... some notebooks work just fine!    We can output_notebook()... make a chart,  and use show(p) to see the chart in the notebook... however,  other notebooks with the same plotting code... charts does not show in the notebook!  (get the  bokeh.io._CommsHandle)
- some plots are being made in loops (wish we had R lattice like "conditioning and grouping")
- Plot type (in this case) happen to be on pandas time series (index = days,  values=counts) .  Something like:
  
  p = figure(height=400, width=900,
      title='Trend of {}'.format(method),
      title_text_font_size = '12pt',
      y_axis_label = 'Count ',
      x_axis_label = 'Time Bucket',
      x_axis_type="datetime")
  
  p.line(df.index, df['id'])
  p.xaxis.axis_label_text_font_size = "12pt"
  p.yaxis.axis_label_text_font_size = "12pt"
  
  show(p)

Python version
'3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)]'

['backports.ssl-match-hostname==3.4.0.2',
 'bcolz==0.11.4',
 'beautifulsoup4==4.4.1',
 'bitarray==0.8.1',
 'bokeh==0.11.0',
 'bottleneck==1.0.0',
 'cdecimal==2.3',
 'ceodbc==2.0.1',
 'certifi==2015.9.6.1',
 'colorama==0.3.3',
 'cycler==0.9.0',
 'cython==0.23.4',
 'decorator==4.0.4',
 'flask==0.10.1',
 'funcsigs==0.4',
 'greenlet==0.4.9',
 'h5py==2.5.0',
 'ipaddress==1.0.14',
 'ipykernel==4.2.2',
 'ipyparallel==4.1.0',
 'ipython-genutils==0.1.0',
 'ipython==4.0.0',
 'ipywidgets==4.1.1',
 'itsdangerous==0.24',
 'jdcal==1.0',
 'jinja2==2.8',
 'jsonschema==2.5.1',
 'jupyter-client==4.1.1',
 'jupyter-console==4.0.3',
 'jupyter-core==4.0.6',
 'jupyter==1.0.0',
 'line-profiler==1.0',
 'lxml==3.4.4',
 'markdown==2.6.2',
 'markupsafe==0.23',
 'matplotlib==1.5.0',
 'memory-profiler==0.37',
 'mistune==0.7.1',
 'mock==1.3.0',
 'msgpack-numpy==0.3.6',
 'msgpack-python==0.4.6',
 'natgrid==0.2.1',
 'nbconvert==4.1.0',
 'nbformat==4.0.1',
 'networkx==1.10',
 'nltk==3.0.5',
 'nose==1.3.7',
 'notebook==4.1.0',
 'numexpr==2.4.4',
 'numpy==1.9.3',
 'openpyxl==2.2.5',
 'palettable==2.1.1',
 'pandas==0.17.1',
 'path.py==8.1.2',
 'patsy==0.4.0',
 'pbr==1.8.1',
 'pickleshare==0.5',
 'pillow==3.0.0',
 'pip==7.1.2',
 'psutil==3.2.2',
 'ptyprocess==0.5',
 'pyflakes==0.9.2',
 'pygments==2.0.2',
 'pyodbc==3.0.10',
 'pyopengl-accelerate==3.1.1a1',
 'pyopengl==3.1.1b1',
 'pyparsing==2.0.3',
 'pyqt4==4.11.4',
 'pyqwt==5.2.1',
 'pyreadline==2.0',
 'pystache==0.5.4',
 'python-dateutil==2.4.2',
 'pytz==2015.7',
 'pywin32==219',
 'pyyaml==3.11',
 'pyzmq==14.7.0',
 'qtconsole==4.1.1',
 'requests==2.8.1',
 'retrying==1.3.3',
 'scikit-image==0.11.3',
 'scikit-learn==0.17',
 'scipy==0.16.1',
 'seaborn==0.6.0',
 'setuptools==18.2',
 'simplegeneric==0.8.1',
 'simplejson==3.8.1',
 'six==1.10.0',
 'sqlalchemy==1.0.9',
 'statsmodels==0.6.1',
 'sympy==0.7.6.1',
 'tables==3.2.2',
 'terminado==0.5',
 'tornado==4.2.1',
 'traitlets==4.0.0',
 'ujson==1.34',
 'vispy==0.4.0',
 'werkzeug==0.10.4',
 'wheel==0.26.0',
 'xlrd==0.9.4',
 'xlwt==1.0.0']

One more added piece of info for my case problem.  I just tried a third browser (Edge) and opened a notebook where the plots were not rendered in the notebook (with either Chrome or IE) after show(p).   Magically,  **without even re-running the notebook**,  the plots were rendered in the notebook as soon as I opened it in Edge!

So.. this seems to have a browser (or browser history) aspect to it,  at least for me.  It still did start after a recent bokeh update.  I will have another user try to open one of my notebooks to see if there is some local cache / history aspect to this.

When I reload the page, I see the following error in dev console: 

```
bokeh-0.11.0.min.js:9 Uncaught TypeError: Cannot read property 'frame' of undefined
window.Bokeh.Bokeh.renderer/glyph/glyph_renderer.e.initialize @ bokeh-0.11.0.min.js:9
window.Bokeh.Bokeh.backbone.e.View @ bokeh-0.11.0.min.js:19
e @ bokeh-0.11.0.min.js:2
n @ bokeh-0.11.0.min.js:4
e @ bokeh-0.11.0.min.js:9
window.Bokeh.Bokeh.common/embed.p @ bokeh-0.11.0.min.js:2
window.Bokeh.Bokeh.common/embed.x @ bokeh-0.11.0.min.js:2
window.Bokeh.Bokeh.common/embed.M @ bokeh-0.11.0.min.js:2
(anonymous function) @ VM1594:58
window.Bokeh.Bokeh.jquery.tt.Callbacks.h @ bokeh-0.11.0.min.js:61
window.Bokeh.Bokeh.jquery.tt.Callbacks.c.fireWith @ bokeh-0.11.0.min.js:61
window.Bokeh.Bokeh.jquery.tt.extend.ready @ bokeh-0.11.0.min.js:61
a @ bokeh-0.11.0.min.js:51
```

Chrome version is 43.0.2357.81 m, Windows 7.

Thanks for all the information, @mattpap is going to make a stab at reproducing/diagnosing notebook issues. 

I have seen this error as well. It happens in Firefox and Chrome also. I can reproduce it if I have the same notebook opened in two different browser tabs or browsers. After you have 2 correctly loaded refresh one it fails.

When I close the notebook and restart the entire Web Browser application and re-open then the notebook it works fine.

Seems to happen some times when a browser session is left open too long and you attempt to reload the notebook.

After a few 'F5' refreshes I managed to get this error in the Browser console log:

```
18:39:49.979 TypeError: Jupyter.notebook.kernel is null
Bokeh</<["common/embed"]</f() bokeh-0.11.0.min.js:2
Bokeh</<["common/embed"]</M() bokeh-0.11.0.min.js:2
inline_js</<() main.min.js:58
Bokeh</<.jquery</</tt.Callbacks/h() bokeh-0.11.0.min.js:61
Bokeh</<.jquery</</tt.Callbacks/c.fireWith() bokeh-0.11.0.min.js:61
Bokeh</<.jquery</</<.ready() bokeh-0.11.0.min.js:61
1 bokeh-0.11.0.min.js:2:23495
```

I think it is related to the internet connection. I have similar issues when by network connection is down... Looking at network traffic, it looks like the browser is searching for:
https://cdn.pydata.org/bokeh/release/bokeh-compiler-0.11.0.min.js
https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.0.min.js
https://cdn.pydata.org/bokeh/release/bokeh-compiler-0.11.0.min.js
Nothing is rendered if files are not found.
Would it be possible to use a local version of the file instead of trying to get them from the web ?

Yes absolutely, you can set the environment variable `BOKEH_RESOURCES=inline` before you run the notebook server, or you can pass `bokeh.resources.INLINE` to as the `resources` argument to `output_notebook`. For a long time `INLINE` resources were the default but we got many requests to make `CDN` (network supplied) resources the default. 

That's not the original error, though.  All, I am traveling this week I am not going to have much if any time to devote to this. But a quick look seems to suggest this might be an avenue to improve:

https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/embed.coffee#L149-L150

It seems as though Jupyter is throwing an exception sometimes when we attempt to init notebook comms. At lest that is how I interpret:

```
Could not open comm  --  Error: Class 1854dd25-3916-46bd-aab3-1729f21a403a not found in registry
```

So a solution might be as simple as putting a `try` block around that javascript call to `_init_comms`, making a console log or logger error if it fails so that if comms init fails at least the normal rendering still occurs. A fuller investigation later might turn up some way to avoid the exception altogether. If anyone has the opportunity to test this idea (which would involve building BokehJS from source), the results would be appreciated. 

I ran into this issue as well. Ubuntu 14.04. Firefox. Clearing browser storage did the trick. Thanks folks. 

Hi @AlJohri , @lindseydi , @PeterSulcs , @rsgoodwin , @ecatmur , @dragoljub , @patrickhoebeke 

We think is issue was resolved in PR #3803 

Long story short, a new Jupyter Notebook release uses a version of JQuery that conflicted with how BokehJS was loaded. If you upgrade to Bokeh 0.11.1 (which has the patch) and still have the problem, please let us know.

Otherwise, thanks so much for the bug help!

Hi,

I believe the problem is still there. I have installed Bokeh 0.11.1 and when I trying to plot. I got the following error:

Javascript error adding output!
TypeError: Cannot read property 'frame' of undefined
See your browser Javascript console for more details.
Out[3]: <Bokeh Notebook handle for In[3]>

And my javascript console shows

Bokeh: all callbacks have finished
(program):74 Bokeh: BokehJS loaded, going straight to plotting
main.min.js:20212 TypeError: Cannot read property 'frame' of undefined(…)
cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.js:62 Bokeh: Registering Jupyter comms for target d621e1e9-8d34-420b-8bd8-e70813a4795

$ ipython3 --version
4.0.3
$ jupyter --version
4.0.6
$ pip3 freeze | grep notebook
notebook==4.1.0

$ pip3 freeze | grep jupyter
jupyter==1.0.0
jupyter-client==4.1.1
jupyter-console==4.1.0
jupyter-core==4.0.6
bokeh==0.11.1

Updated: It's my bad, not bokeh's. In my notebook file, I accidentally use:

``` python
p = figure(title="Simple Sin Wave", plot_height = 300, plot_width = 600)
p.line(x,y, color="red", line_width = 1)
show(p)
```

That causes the problem. However, my next cell's grammar is correct but it does not render any plot either due to the previous error. Is that possible to make the second correct plot work even the first plot fails? 

One idea occurred to me is that there sometimes seems to be an error when jupyter comms are created. Possibly just putting the attempt in a `try`/`catch` with a JS console warning that comms failed would. Comms obviously wouldn't work in those cases but at least it wouldn't mess up further plotting that did not rely on them. 

>  For a long time INLINE resources were the default but we got many requests to make CDN (network supplied) resources the default.

Little nit: It would be good to update the docstring. It still says INLINE is the default in 0.11.1 (http://bokeh.pydata.org/en/0.11.1/docs/reference/io.html#bokeh.io.output_notebook)

@parente It would, that location was overlooked. Could you submit a PR with the change?

I am relabeling as a `bug`. The `try`/`catch` around the comms should be added no matter what, I want to make sure the task it not lost before the `0.12` release. 

Hi @AlJohri , @lindseydi , @PeterSulcs , @rsgoodwin , @ecatmur , @dragoljub , @patrickhoebeke 

I have made a PR #4144 that adds the `try` / `except` around notebook comms init. If any of you are familiar with the build process and can try it out (you'd need to use `BOKEH_RESOURCES=inline`) that would extremely appreciated. I am not able to reproduce the issue locally, despite trying. I had to force an error by raising an exception manually to "test" it. 

I have marked this closed and completed because I believe #4144 will prevent BokehJS from falling over in the notebook when there are comms problems. However, _I could never reliably reproduce the initial issue_. Any testing or feedback from anyone in this issue is extremely valuable. This change will be in a "dev build" available tomorrow. 

Hi: I'm having the same problem, I think.  It seemed to originally be caused by what I think was an illegal figure specification:

`p = figure(x_range=(0, 50), y_range=(0, 50),title='a',width=50,height=50)
show(p)` 

It gave me some javascript errors I can't seem to reproduce.  All that comes across in the console is:

`<Bokeh Notebook handle for In[14]>`

It seems like my console has a message "Could not open comm".  It's not working even if I close an restart jupyter.

Here's what I'm using:
ipython --version
4.0.0
jupyter --version
4.0.6
pip freeze notebook
notebook==4.0.6
pip freeze jupyter
jupyter==1.0.0
jupyter-client==4.1.1
jupyter-console==4.1.0
jupyter-core==4.0.6
bokeh==0.11.1

Any suggestions would be appreciated!

Are you trying a dev build or master? The potential fix is not In any official release yet. 

> On Apr 14, 2016, at 16:35, Ben Batorsky notifications@github.com wrote:
> 
> Hi: I'm having the same problem, I think. It seemed to originally be caused by what I think was an illegal figure specification:
> 
> p = figure(x_range=(0, 50), y_range=(0, 50),title='a',width=50,height=50)
> show(p)
> 
> It gave me some javascript errors I can't seem to reproduce. All that comes across in the console is:
> 
> <Bokeh Notebook handle for In[14]>
> 
> It seems like my console has a message "Could not open comm". It's not working even if I close an restart jupyter.
> 
> Here's what I'm using:
> ipython --version
> 4.0.0
> jupyter --version
> 4.0.6
> pip freeze notebook
> notebook==4.0.6
> pip freeze jupyter
> jupyter==1.0.0
> jupyter-client==4.1.1
> jupyter-console==4.1.0
> jupyter-core==4.0.6
> bokeh==0.11.1
> 
> Any suggestions would be appreciated!
> 
> —
> You are receiving this because you modified the open/close state.
> Reply to this email directly or view it on GitHub

Ah, okay, that's the issue, thanks for getting back to me on that.  I also noticed that if I don't clear the output for the failed figure, it won't display any other figures.  That's in the master, though.

Same problem here with the master branch

Same problem here with Bokeh 0.11.1. If I create a new notebook using the same browser using the same kernel it works fine so it is not really reproducible.

I was having a very similar issue, but using "Close and Halt" from the jupyter notebook menu and then reopening the notebook seemed to make the problem go away.

Just as a note for people still having this problem: If I clear the output from cells in my notebook and then re-run, it seems to work.  May be an issue with how jupyter stores cell output.

Just to be clear, the fix mentioned in this issue is still only in master, and not in `0.11.1` Is anyone besides @fretchen reporting this problem on GH master? If so, can anyone try to provide steps to reproduce? 

@bryevdv - I still see this problem with the current master `0.12.0dev10-14-g3100544`, both for firefox and safari. If I open the nb again in a new tab the first plot show up, but none of the consecutive ones.

I'll try to come up with a minimal or at least shareable failing example later this evening.

that would be extremely helpful. I am about to merge a PR to let unminified resources work in the notebook, which is necessary to have any shot at debugging this.

Hello, 

I experienced this issue with my comms failing consistently so I am providing some information about my platform so that the assignee can attempt to reproduce the error. 

Bokeh: 12.0
Python 3.4
Anaconda 2.5.0 (32-bit)
OS: Ubuntu 14.04 (32-bit) in Virtual Box VM
VM:
-  1114 MB RAM
- 1 CPU execution cap 100%

Notebooks running on Client side from JupyterHub
jupyter==1.0.0  
jupyter-client==4.2.2  
jupyter-console==4.1.1  
jupyter-core==4.1.0  
jupyterhub==0.6.1 

Browser on client side:

Chrome -51.0.2704.103 m

Example Code (code modified omitting company data):

import pandas as pd
import pyodbc as pdb
import bokeh
from pandas import DataFrame
from bokeh.charts import Bar
from bokeh.plotting import figure, show, output_notebook
from numpy import nan
from bokeh.io import output_notebook, show
from bokeh import *
from bokeh.models import PrintfTickFormatter
from bokeh.models.formatters import NumeralTickFormatter, DatetimeTickFormatter
from prettypandas import PrettyPandas
import datetime
from bokeh.io import \* 

DataFrameOfAtLeast49LinesAndDateColumn = DataFrame of columns ('Total', 'PartofTotal1','PartofTotal2','Date')

DataFrameOfAtLeast49LinesAndDateColumn['Calculation 1'] = \
    DataFrameOfAtLeast49LinesAndDateColumn['PartofTotal1']/DataFrameOfAtLeast49LinesAndDateColumn['Total']
DataFrameOfAtLeast49LinesAndDateColumn['Calculation 2'] = \
    DataFrameOfAtLeast49LinesAndDateColumn['PartofTotal2']/DataFrameOfAtLeast49LinesAndDateColumn['Total']
ProblematicGraphFrame = \
    DataFrameOfAtLeast49LinesAndDateColumn[['Date','Calculation 1',
                             'Calculation 2']]

ProblematicGraph = figure(x_axis_type="datetime",width=750, height=350)

ProblematicGraph.line(ProblematicGraphFrame['Date'],
                                ProblematicGraphFrame['Calculation 1'],
                                 color='#89169f', legend='Calculation 1')
ProblematicGraph.line(ProblematicGraphFrame['Date'],
                                ProblematicGraphFrame['Calculation 2'],
                                 color = '#903c18', legend='Calculation 2')
ProblematicGraph.title.text = "Historical Weekly Fill Rate"
ProblematicGraph.grid.grid_line_alpha=0.9
ProblematicGraph.xaxis.axis_label = 'Date'
ProblematicGraph.yaxis.axis_label = 'Fill Rate Percentage'
ProblematicGraph.legend.location = "bottom_right"
ProblematicGraph.yaxis[0].formatter = NumeralTickFormatter(format="0%")
ProblematicGraph.xaxis[0].formatter = DatetimeTickFormatter(formats=dict(days=["%a,  %b %d"]))
output_notebook()
show(ProblematicGraph)

@cenveoanalyst what happens:
- if you do `output_notebook` at the top? 
- if you run `output_notebook` only after the show?
- if you use INLINE resources instead of CDN?

After some investigation, I have a possible idea that the reason for the failure is that BokehJS is not fully loaded when `show` is called.

Anyone else on this issue that can try these things out would be appreciated. 

@bryevdv Let me see what I can come up in trying your examples. How can I use INLINE resources instead of CDN? Are INLINE resources available when I download the package or do I have to build Bokeh on my machine?

@cenveoanalyst:

```
from bokeh.resources import INLINE
output_notebook(resources=INLINE)
```

another thing to try: put a `time.sleep(1)` at this line in your installed bokeh library:

https://github.com/bokeh/bokeh/blob/master/bokeh/util/notebook.py#L32

Last other possible modification to try: comment out these three lines:

https://github.com/bokeh/bokeh/blob/master/bokeh/io.py#L336-L338

More info: if I shut off my wifi and run an example notebook, I get a message saying BokehJS is loaded (even though it's not), and then no plot, and this console output:

<img width="677" alt="screen shot 2016-07-07 at 5 57 48 pm" src="https://cloud.githubusercontent.com/assets/1078448/16672553/6a81fa44-446c-11e6-8303-e5c0fbbe5a81.png">

 If I save, exit, turn on my wifi, then reload the saved notebook, the plot shows up without any execution. I believe this is consistent with what has been reported as well. So I may have some ideas of the changeset that precipitated this, either way I definitely thing the _current_ issued (there may have been a different cause earlier on) is that BokehJS is simply not actually loaded at the time `show` is called. 

ping @mattpap 

another question for the group: when it fails, do it say "Loading BokehJS ..." or "BokehJS successfully loaded"?

Also if anyone is especially adventurous, here is a diff that could be applied to test this theory:

```
diff --git a/bokeh/__init__.py b/bokeh/__init__.py
index 0fe135c..99dc85c 100644
--- a/bokeh/__init__.py
+++ b/bokeh/__init__.py
@@ -61,3 +61,5 @@ def license():
     from os.path import join
     with open(join(__path__[0], 'LICENSE.txt')) as lic:
         print(lic.read())
+
+__nb_loaded = False
diff --git a/bokeh/io.py b/bokeh/io.py
index beafb7a..891802d 100644
--- a/bokeh/io.py
+++ b/bokeh/io.py
@@ -331,6 +331,9 @@ def _show_notebook_with_state(obj, state):
         snippet = autoload_server(obj, session_id=state.session_id_allowing_none, url=state.url, app_path=state.app_path)
         publish_display_data({'text/html': snippet})
     else:
+        import bokeh
+        if not bokeh.__nb_loaded:
+            raise RuntimeError("BokehJS not actually loaded")
         comms_target = make_id()
         publish_display_data({'text/html': notebook_div(obj, comms_target)})
         handle = _CommsHandle(get_comms(comms_target), state.document, state.document.to_json())
diff --git a/bokeh/util/notebook.py b/bokeh/util/notebook.py
index 3e75be2..cb14fd5 100644
--- a/bokeh/util/notebook.py
+++ b/bokeh/util/notebook.py
@@ -30,6 +30,13 @@ def load_notebook(resources=None, verbose=False, hide_banner=False):
     publish_display_data({'text/html': html})
     publish_display_data({'application/javascript': js})

+FINALIZE_JS = """
+Bokeh.$("#%s").text("BokehJS successfully loaded");
+var kernel = IPython.notebook.kernel
+kernel.execute("import bokeh; bokeh.__nb_loaded = True");
+"""
+
 def _load_notebook_html(resources=None, verbose=False, hide_banner=False):
     global _notebook_loaded

@@ -67,12 +74,10 @@ def _load_notebook_html(resources=None, verbose=False, hide_banner=False):
         hide_banner   = hide_banner,
     )

-    finalize_js = """Bokeh.$("#%s").text("BokehJS successfully loaded");""" % element_id
-
     js = AUTOLOAD_JS.render(
         js_urls  = resources.js_files,
         css_urls = resources.css_files,
-        js_raw   = resources.js_raw + [finalize_js],
+        js_raw   = resources.js_raw + [FINALIZE_JS % element_id],
         css_raw  = resources.css_raw_str,

```

Just quick comments...

You should use the Jupyter namespace...

```
var kernel = IPython.notebook.kernel
```

ohohoh... 

```
kernel.execute("import bokeh; bokeh.__nb_loaded = True")
```

this remind me when I wrote js notebook extensions executing python script on the kernel side... fun... but it feels like a hack/workaround... or maybe you are just trying to probe the concept here about the possible problem and fix...

What about triggering an event on the JS side when the BokehJS finalize its load and then look for that event (somehow) using the comm machinery?

>  but it feels like a hack/workaround... or maybe you are just trying to probe the concept here about the possible problem and fix...

Basically at the moment, but OTOH I am not sure there is anything better. I was trying to find other solutions yesterday and did not come up with much of anything. I'd rather not rely on comms for BokehJS loading I am not sure how that would interact with rendered notebooks. 

Hi @AlJohri , @lindseydi , @PeterSulcs , @rsgoodwin , @ecatmur , @dragoljub , @patrickhoebeke (sorry for the big ping) If anyone has any opportunity to try any of the experiments about it would be incredibly appreciated. I still don't have a reliable way to reproduce this, so help evaluating this possible avenue is critical. 

Well, this is a nightmare to try and test and fix. I  am close to making a controversial suggestion, which is to restore notebooks to using inline resources by default. AFAICT that is the only technical way to guarantee that the resources are correctly loaded first. But also the lack of a script `onerror` facility in JS means there is no good way to even detect or try to correct on failure to load, either. I've tried an ajax call to fetch the script as text but naturally that runs into CORS issues, and I've tried various hacky timeout ideas, but those attempts have only made things worse. 

Confirmation that inline resources solves the problem would be helpful, though. 

Inline resources does not solve the problem for me.
`from bokeh.plotting import figure, show, output_notebook`
`from bokeh.models import GMapPlot`
`from bokeh.resources import INLINE`
`output_notebook(resources=INLINE)`
`plot = GMapPlot()`
`plot.api_key = 'AIzaSyD2aUsVinTC5QYO6X_GDMqyJcjxSi6cHQo`
`show(plot)`

Out: `<Bokeh Notebook handle for In[2]>` (no figure shown)

Chrome console:
![image](https://cloud.githubusercontent.com/assets/19699163/16717110/78bfc260-4752-11e6-995f-e64dd82cb29d.png)


Resolving patch:
diff --git a/bokeh/io.py b/bokeh/io.py
--- a/bokeh/io.py
+++ b/bokeh/io.py
@@ -47,6 +47,8 @@
 
 _state = State()
 
+_nb_loaded = False
+
 #-----------------------------------------------------------------------------
 # Local utilities
 #-----------------------------------------------------------------------------
@@ -325,12 +327,28 @@ def _show_file_with_state(obj, state, new, controller):
     filename = save(obj, state=state)
     controller.open("file://" + filename, new=_new_param[new])
 
+_NB_LOAD_WARNING = """
+
+BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this
+may be due to a slow or bad network connection. Possible fixes:
+
+* ALWAYS run `output_notebook()` in a cell BY ITSELF, AT THE TOP, with no other code
+* re-rerun `output_notebook()` to attempt to load from CDN again, or
+* use INLINE resources instead, as so:
+
+    from bokeh.resources import INLINE
+    output_notebook(resources=INLINE)
+"""
+
 def _show_notebook_with_state(obj, state):
     if state.server_enabled:
         push(state=state)
         snippet = autoload_server(obj, session_id=state.session_id_allowing_none, url=state.url, app_path=state.app_path)
         publish_display_data({'text/html': snippet})
     else:
+        if not _nb_loaded:
+            warnings.warn(_NB_LOAD_WARNING)
+            return
         comms_target = make_id()
         publish_display_data({'text/html': notebook_div(obj, comms_target)})
         handle = _CommsHandle(get_comms(comms_target), state.document, state.document.to_json())
diff --git a/bokeh/util/notebook.py b/bokeh/util/notebook.py
--- a/bokeh/util/notebook.py
+++ b/bokeh/util/notebook.py
@@ -30,6 +30,14 @@ def load_notebook(resources=None, verbose=False, hide_banner=False):
     publish_display_data({'text/html': html})
     publish_display_data({'application/javascript': js})
 
+FINALIZE_JS = """
+Bokeh.$("#%s").text("BokehJS successfully loaded");
+var kernel = Jupyter.notebook.kernel
+if (kernel.execute !== undefined) {
+    kernel.execute("import bokeh.io; bokeh.io._nb_loaded = True");
+}
+"""
+
 def _load_notebook_html(resources=None, verbose=False, hide_banner=False):
     global _notebook_loaded
 
@@ -67,13 +75,12 @@ def _load_notebook_html(resources=None, verbose=False, hide_banner=False):
         hide_banner   = hide_banner,
     )
 
-    finalize_js = """Bokeh.$("#%s").text("BokehJS successfully loaded");""" % element_id
-
     js = AUTOLOAD_JS.render(
         js_urls  = resources.js_files,
         css_urls = resources.css_files,
-        js_raw   = resources.js_raw + [finalize_js],
+        js_raw   = resources.js_raw + [FINALIZE_JS % element_id],
         css_raw  = resources.css_raw_str,
+        force    = 1,
     )
 
     return html, js


Test patch:
diff --git a/bokeh/tests/test_io.py b/bokeh/tests/test_io.py
--- a/bokeh/tests/test_io.py
+++ b/bokeh/tests/test_io.py
@@ -349,6 +349,28 @@ def test_no_notebook(self, mock_get_browser_controller,
         self._check_func_called(mock__show_server_with_state, ("obj", s, "new", "controller"), {})
         self._check_func_called(mock__show_file_with_state, ("obj", s, "new", "controller"), {})
 
+    @patch('warnings.warn')
+    @patch('bokeh.util.browser.get_browser_controller')
+    def test_ShowNotebookWithState_bokehjs_load_failed(self, mock_get_browser_controller, mock_warn):
+        mock_get_browser_controller.return_value = "controller"
+        s = io.State()
+        s.output_notebook()
+        io._show_with_state("obj", s, "browser", "new")
+        self.assertTrue(mock_warn.called)
+        self.assertEqual(mock_warn.call_args[0], ("""
+
+BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this
+may be due to a slow or bad network connection. Possible fixes:
+
+* ALWAYS run `output_notebook()` in a cell BY ITSELF, AT THE TOP, with no other code
+* re-rerun `output_notebook()` to attempt to load from CDN again, or
+* use INLINE resources instead, as so:
+
+    from bokeh.resources import INLINE
+    output_notebook(resources=INLINE)
+""",))
+        self.assertEqual(mock_warn.call_args[1], {})
+
 class Test_ShowFileWithState(DefaultStateTester):
 
     @patch('os.path.abspath')
@@ -389,7 +411,9 @@ def test_no_server(self, mock_notebook_div, mock_publish_display_data, mock_get_
         s = io.State()
         mock_notebook_div.return_value = "notebook_div"
 
+        io._nb_loaded = True
         io._show_notebook_with_state("obj", s)
+        io._nb_loaded = False
         self._check_func_called(mock_publish_display_data, ({"text/html": "notebook_div"},), {})
 
 class Test_ShowServerWithState(DefaultStateTester):