简体   繁体   中英

Bokeh Failed to Load Generated HTML Page to the Browser

I am using bokeh to generate a plot and save to a disk and then show it on the browser. A new page will open in the browser and then nothing is display on the screen except the title of that page.

Here is the code I wrote:

from bokeh.plotting import figure, show, output_file
p = figure(title="Basic Title", plot_width=300, plot_height=300)
p.circle([1,2], [3,4])
output_file("test.html")
show(p)

来自浏览器的屏幕截图 日志中的 Java 脚本错误

As Chrome developer console mentions, your test.html file fails at fetching resources (Bokeh CSS and JS files). The version of Bokeh you use is probably the culprit here.

Try reinstalling Bokeh with pip install bokeh and it should work.

Otherwise, if you don't want or cannot reinstall it, you can manually edit your HTML file so that it points to the correct resources:

  • https://cdn.bokeh.org/bokeh/release/bokeh-0.12.5.min.css for the CSS
  • https://cdn.bokeh.org/bokeh/release/bokeh-0.12.5.min.js for the JS

You are evidently running of Bokeh installed from GitHub source. In this case you must use "inline" resources. CDN resources are only published for full releases, release candidates, and "dev" builds. We do not publish CDN resources for every commit, so there will never be versions like dev13+2.<hash>.min.js available on CDN.

An easy way to use inline resources is to set the BOKEH_RESOURCES environment variable:

BOKEH_RESOURCES=inline python myscript.py

Of course the other alternative is to install a real release instead of installing from source.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM