Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't inline Bokeh in IPython

I have the latest Bokeh and IPython installed, and I try running the following: (all of these imports are relevant later on in the code)

import pandas as pd
import datetime
import matplotlib.pyplot as plt
import itertools as itt
import bokeh.plotting as bk
bk.output_notebook()

xs = [0,1,2,3,4,5]
ys = [x**2 for x in xs]

p.line(xs, ys, line_width=2)
p.circle(xs,ys)
bk.show(p)

After running these 2 cells, I get:

Javascript error adding output! ReferenceError: Bokeh is not defined See your browser Javascript console for more details.

So, I run the console and see this:

ReferenceError: Bokeh is not defined Stack trace: @http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302 line 4 > eval:1:1 .globalEval@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:4:4231 .domManip@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:5:21389 .append@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:5:18980 OutputArea.prototype._safe_append@http://localhost:8888/static/notebook/js/outputarea.js?v=20150304125302:414:13 OutputArea.prototype.append_display_data@http://localhost:8888/static/notebook/js/outputarea.js?v=20150304125302:534:13 OutputArea.prototype.append_output@http://localhost:8888/static/notebook/js/outputarea.js?v=20150304125302:320:13 OutputArea.prototype.handle_output@http://localhost:8888/static/notebook/js/outputarea.js?v=20150304125302:234:9 CodeCell.prototype.get_callbacks/<.iopub.output@http://localhost:8888/static/notebook/js/codecell.js?v=20150304125302:456:21 Kernel.prototype._handle_output_message@http://localhost:8888/static/services/kernels/kernel.js?v=20150304125302:997:13 .proxy/i@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:4:5486 Kernel.prototype._handle_iopub_message@http://localhost:8888/static/services/kernels/kernel.js?v=20150304125302:1024:13 Kernel.prototype._finish_ws_message@http://localhost:8888/static/services/kernels/kernel.js?v=20150304125302:866:17 .proxy/i@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:4:5486 deserialize@http://localhost:8888/static/services/kernels/serialize.js?v=20150304125302:60:13 Kernel.prototype._handle_ws_message@http://localhost:8888/static/services/kernels/kernel.js?v=20150304125302:857:9 .proxy/i@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:4:5486 outputarea.js:416

Before seeing this, bk.show(p) displayed a distorted plot, saying "Hello Word", but all the buttons were deformed. matplotlib works fine.

like image 374
golanor Avatar asked May 15 '26 06:05

golanor


1 Answers

This issues was addressed in https://github.com/bokeh/bokeh/issues/2024 which moved the code that loads BokehJS into output_notebook instead of just trying to do it when bokeh is imported. However, I would still recommend putting bk.output_notebook in its own ipython cell with nothing else. I am going to update the documentation to reflect this recommendation soon. The issue is that Bokeh uses IPython's "publish" mechanism to load itself, and if you put other things in a cell that also have output, it can interfere with that. Thats just the way IPython notebook works, there's not really anything else to do but to suggest putting output_notebook on its own, so it is output is guaranteed to be correct.

like image 196
bigreddot Avatar answered May 18 '26 14:05

bigreddot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!