问题描述
我试图将bokeh情节嵌入到我的django应用程序中.我按照 Bokeh网站和另一个问题.
I was trying to embed a bokeh plot into my django app. I followed the instructions given on Bokeh website and another question.
我在浏览器控制台上遇到以下错误,但未获得任何绘图输出:
I am getting the following error on my browser console and not getting any plot output:
Uncaught TypeError: Bokeh.safely is not a function
at HTMLDocument.fn (localhost/:15)
我不是JS家伙,但Bokeh.safely存在于Bokeh生成的脚本中.我已经附上了最后生成的脚本:
I am not a JS guy but Bokeh.safely is present in the script generated by Bokeh. I have attached the script generated at the end:
我的views.py文件:
My views.py file:
from django.shortcuts import render
from bokeh.plotting import figure
from bokeh.resources import CDN
from bokeh.embed import components
def showGraph(request):
arr = [1,4,9,16,25,36]
y = [1,2,3,4,5,6]
plot = figure()
plot.line(arr, y)
script, div = components(plot, CDN)
return render(request, "data_collection/simple_chart.html", {"script": script, "div": div})
simplechart.html文件:
simplechart.html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bokeh example</title>
<link rel="stylesheet" href="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.0.min.css">
<link rel="stylesheet" href="http://cdn.bokeh.org/bokeh/release/bokeh-widgets-0.12.0.min.css">
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.0.min.js"></script>
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-widgets-0.12.0.min.js"></script>
{{ script | safe }}
</head>
<body>
{{ div | safe }}
</body>
</html>
散景生成的脚本:
(function(){
var fn = function(){
Bokeh.safely(function(){
var docs_json = {....json.....};
var render_items = [
{"docid": "27fe9292-3142-4617-b273-f9d932e47df3", "elementid": "7b2ef36e-a7d2-4a6b-88e6-186edecde6ca",
"modelid": "741db3b0-26ce-45c1-86b4-d95394c7331f"}];
Bokeh.embed.embed_items(docs_json, render_items);
});
};
if (document.readyState != "loading") fn();
else document.addEventListener("DOMContentLoaded", fn);
})();
推荐答案
您正在从CDN的simplechart.html
模板中加载BokehJS的0.12.0
版本,但是几乎可以肯定的是,您正在使用更新版本的BokehJS. Python Bokeh库比. BokehJS和(Python)Bokeh库的版本必须匹配.
You are loading version 0.12.0
of BokehJS from CDN in your simplechart.html
template, but it's almost certainly the case that you are using a newer version of the Python Bokeh library than that. The versions of BokehJS and (Python) Bokeh library must match.
这篇关于Django:Bokeh.safely不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!