我正在使用 Bokeh component获取用于在 html 报告中嵌入图形的 script 和 div 标记。该报告是用 elementtree 构建的.
问题是 component 返回 script 和 div 作为字符串,这意味着我不能方便地使用 SubElement 制作适当的元素。如果您直接写入文件,这些字符串可以正常工作,但我无法使用 etree 来解析字符串并确定属性。感觉笨重。
还有其他人遇到过这个吗?如果有一种方法可以让组件返回两个字典,那就太好了,就像这样:
script = {
tag='script',
type='text/javascript',
data=#script contents here
}
id= {
tag='div',
class='bk-root',
id='6c76dbfe-52ec-4388-b408-a3142466196e'
}
请您参考如下方法:
检查 reference documentation 总是一个好主意, components 已经有关键字参数标志,用于将信息作为原始数据而不是 HTML 标签提供:
wrap_script (boolean, optional) :
If True, the returned javascript is wrapped in a script tag.
(default: True)
wrap_plot_info (boolean, optional) : If True, returns ``<div>`` strings.
Otherwise, return dicts that can be used to build your own divs.
(default: True)
If False, the returned dictionary contains the following information:
{
'modelid': 'The model ID, used with Document.get_model_by_id',
'elementid': 'The css identifier the BokehJS will look for to target the plot',
'docid': 'Used by Bokeh to find the doc embedded in the returned script',
}
