从 Bokeh Donut 对象获取组件

Getting component from Bokeh Donut object

我写了一个小应用程序来可视化一些数据。该应用程序是 Flask 中的一个小型 Web 应用程序,我想在响应页面中提供散景组件。类似于:

script, div = components(figure)
return render_template('plot.html', div_plot=div, script_plot=script)

这种方法似乎适用于简单的图表或图形,如下例所示,我可以在其中使用图形对象中的属性创建绘图。像

fig = figure(plot_width=900, plot_height=200, tools=tools,x_axis_type='datetime')
fig.line('date', 't1', source=source_static)
script, div = components(fig)

不幸的是,对于 Donut 对象,事情似乎有所不同,您只能像这样创建 Donut 对象

pie_chart = Donut(data)
show(pie_chart)

如何从 Donut 获取 div 和脚本?我如何将它嵌入现有的 html 页面?

最后我自己找到了解决方案。 显然没有必要通过 'figure' 对象。相反,一个人可以做

from bokeh.charts import Donut
import pandas as pd

data = pd.Series( ...  some data ... )
script, div = components(Donut(data))

傻我。 希望这会对某人有所帮助。