【发布时间】:2015-04-27 01:35:32
【问题描述】:
以下脚本(来自this SO answer)生成一个简单的应用程序散景图。
如何将输出保存到独立的 html 文件中?
import bokeh.plotting as bk
from bokeh.models import ColumnDataSource, Plot
from bokeh.models.widgets import Select, AppVBox
from bokeh.simpleapp import simpleapp
data = {"a": {"x": [1,2,3], "y": [1,2,3]},
"b": {"x": [3,2,1], "y": [1,2,3]},
"c": {"x": [2,2,2], "y": [1,2,3]},}
options = ["a", "b", "c"]
select1 = Select(name = 'ticker1', value = options[0], options = options)
@simpleapp(select1)
def test_layout(ticker1):
p = bk.figure(title = "layout test")
chart_data = data[ticker1]
df = ColumnDataSource(data = chart_data)
p.circle(x = chart_data["x"], y = chart_data["y"])
return {'plot': p}
@test_layout.layout
def layout(app):
return AppVBox(app=app, children=['ticker1', 'plot'])
test_layout.route("/bokeh/layout/")
我尝试更改layout(app) 以使用file_html。这会生成初始图,但组合框不起作用。我认为file_html 仅适用于单个绘图对象,不适用于我正在使用的simpleapp。
from bokeh.embed import file_html
from bokeh.resources import CDN
def layout(app):
# save standalone html
html = file_html(AppVBox(app=app, children=['ticker1', 'plot']), CDN, "title")
f = open("bokeh_standalone.html", "w")
f.write(html)
f.close
【问题讨论】: