gpt4 book ai didi

python - 将 Bokeh 组件与 elementtree 一起使用

转载 作者:太空宇宙 更新时间:2023-11-04 02:57:24 25 4
gpt4 key购买 nike

我正在使用 Bokeh component获取用于在 html 报告中嵌入图形的 scriptdiv 标记。该报告是用 elementtree 构建的.

问题是 component 返回 scriptdiv 作为字符串,这意味着我不能方便地使用 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',
}

关于python - 将 Bokeh 组件与 elementtree 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41968135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com