将散景组件与 elementtree 一起使用

Use bokeh components with elementtree

我正在使用散景 component to get script and div tags for embedding graphs in an html report. The report is built with elementtree

问题是 component returns scriptdiv 作为字符串,这意味着我不能方便地使用 SubElement 来制作适当的元素。如果您直接写入文件,这些字符串可以正常工作,但我无法使用 etree 来解析字符串并确定属性。感觉笨重。

还有其他人 运行 参与其中吗?如果有一种方法可以将组件添加到 return 两个字典,那就太好了,就像这样:

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',
    }