Python 从Bokeh Donut对象获取组件

Python 从Bokeh Donut对象获取组件,python,bokeh,Python,Bokeh,我写了一个小应用程序来可视化一些数据。该应用程序是Flask中的一个小型web应用程序,我希望在响应页面中提供bokeh组件。比如: script, div = components(figure) return render_template('plot.html', div_plot=div, script_plot=script) 这种方法似乎适用于简单的图表或图形,如下面的示例,我可以使用figure对象中的属性创建绘图。差不多 fig = figure(plot_width=900,

我写了一个小应用程序来可视化一些数据。该应用程序是Flask中的一个小型web应用程序,我希望在响应页面中提供bokeh组件。比如:

script, div = components(figure)
return render_template('plot.html', div_plot=div, script_plot=script)
这种方法似乎适用于简单的图表或图形,如下面的示例,我可以使用figure对象中的属性创建绘图。差不多

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)
不幸的是,对于甜甜圈对象,情况似乎不同,您只能这样创建甜甜圈对象

pie_chart = Donut(data)
show(pie_chart)

如何从甜甜圈中获取div和脚本?如何将其嵌入到现有的html页面中?

最终我自己找到了解决方案。 显然,没有必要通过“图形”对象。相反,我们可以这样做

from bokeh.charts import Donut
import pandas as pd

data = pd.Series( ...  some data ... )
script, div = components(Donut(data))
我真傻。 希望这能帮助别人