【发布时间】:2017-08-18 03:57:07
【问题描述】:
我正在学习 Bokeh,我想让示例 'stocks' 脚本 https://demo.bokeh.org/stocks 生成一个独立的 html 文件...我添加了以下代码:
from bokeh.embed import components
plots = [corr, ts1, ts2]
script, div = components(plots)
print(script)
print(div)
html = """<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bokeh Scatter Plots</title>
<link rel="stylesheet" href="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.6.min.css" type="text/css" />
<script type="text/javascript" src="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.6.min.js"></script>
<!-- COPY/PASTE SCRIPT HERE -->
{}
</head>
<body>
<!-- INSERT DIVS HERE -->
{}
</body>
</html>""".format(script, div)
with open("plotstock.html", "w") as f:
f.write(html)
在脚本的底部,这适用于在http://docs.bokeh.org/en/latest/docs/user_guide/embed.html 找到的一个更简单的示例(没有小部件导入),但对于股票脚本我得到错误:
散景错误
模型“PreText”不存在。这可能是由于在首次使用之前未注册小部件或自定义模型。**
如果我删除对这个小部件的引用,我会为下一个小部件(选择小部件)收到相同的错误...
我可以在散景服务器中运行此脚本,并将数据本地化,但嵌入是问题...
生成的 html 看起来确实很完整,包含数据和组件部分:
<head>
<meta charset="utf-8">
<title>Bokeh Scatter Plots</title>
<link rel="stylesheet" href="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.6.min.css" type="text/css" />
<script type="text/javascript" src="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.6.min.js"></script>
<!-- COPY/PASTE SCRIPT HERE -->
<script type="text/javascript">
(function() {
var fn = function() {
Bokeh.safely(function() {
var docs_json = {"15b39cbd-8b49-4761-9152-f666c6fb1d9a":{"roots": {"references":[{"attributes":{"data_source":{"id":"f6f697cf-6d00-4218-94c1- 18c7e97d7e16","type":"ColumnDataSource"},"glyph":{"id":"3764347f-7617-42a8-a1d4- 0a6b255fc47d","type":"Line"},"hover_glyph":null,"muted_glyph":null,"nonselection_ glyph":{"id":"461527a6-e0fe-4159-89a8- c748b3f16335","type":"Line"},"selection_glyph":null},"id":"a6991b17-5e11-4864- 92ed-85b29f7fe737","type":"GlyphRenderer"},{"attributes":{"months": [0,4,8]},"id":"a3ac5382-f490-408f-b608-f3cdca26772b","type":"MonthsTicker"}, {"attr .... ["87c565c2-e8d1-41ea-958d-ea09daa88b3a"]},"title":"Stocks","version":"0.12.6"}};
var render_items = [{"docid":"15b39cbd-8b49-4761-9152-f666c6fb1d9a","elementid":"ac68790a-4571-49cb-8d1c-08c6f3a9d711","modelid":"a5ab1659-6d31-4869-8d5d-184d27fd5732"}, {"docid":"15b39cbd-8b49-4761-9152-f666c6fb1d9a","elementid":"202aa28c-793d-46df-99ed-30cc4d62b827","modelid":"c22f84ba-56d9-49ab-9d81-314546cfec5c"}, {"docid":"15b39cbd-8b49-4761-9152-f666c6fb1d9a","elementid":"725a58d5-6c34-4f56-8d82-64ebef5c4e46","modelid":"e1fc4190-8882-4d48-be12-b46f9817d525"}];
Bokeh.embed.embed_items(docs_json, render_items);
});
};
if (document.readyState != "loading") fn();
else document.addEventListener("DOMContentLoaded", fn);
})();
</script>
</head>
<body>
<!-- INSERT DIVS HERE -->
('\n<div class="bk-root">\n <div class="bk-plotdiv" id="ac68790a-4571-49cb-8d1c-08c6f3a9d711"></div>\n</div>', '\n<div class="bk-root">\n <div class="bk-plotdiv" id="202aa28c-793d-46df-99ed-30cc4d62b827"></div>\n</div>', '\n<div class="bk-root">\n <div class="bk-plotdiv" id="725a58d5-6c34-4f56-8d82-64ebef5c4e46"></div>\n</div>')
</body>
</html>
谁能告诉我发生了什么或有什么想法?
谢谢。
【问题讨论】: