简体   繁体   English

该<script> tag doesn't seem to work in bokeh Div

[英]the <script> tag doesn't seem to work in bokeh Div

I'm using bokeh to draw some interactive plots, and I also wanna add some html div as description for the plot. 我正在使用bokeh绘制一些交互式图,并且我还想添加一些html div作为该图的描述。 Part of my code: 我的部分代码:

from bokeh.io import show
from bokeh.layouts import widgetbox
from bokeh.models.widgets import Div
div = Div(text="""<p>Title</p><script type="text/javascript">document.write("hi")</script>""")
show(widgetbox(div))

I excepted the output would be: 我除外的输出将是:

Title
hi

But I only got: 但是我只有:

Title

Could someone please help me? 有人可以帮我吗?

This is not possible. 这是不可能的。 Bokeh Div objects only set innerHTML with the text given, as-is. Bokeh Div对象仅按原样设置具有给定文本的innerHTML In order to have a script execute, additional work must happen. 为了执行脚本,必须进行其他工作。 See, for instance, the answers to Executing <script> elements inserted with .innerHTML . 例如,请参阅插入.innerHTML的执行<script>元素的答案。 Bokeh is extensible, so it is possible you could create a Custom Extension that does the required extra work to cause scripts to be evaluated. Bokeh是可扩展的,因此有可能您可以创建一个“ 自定义扩展” ,以执行所需的额外工作来评估脚本。

Alternatively if you embed your Bokeh document in a custom template, you could put the script in template. 或者,如果将Bokeh文档嵌入自定义模板中,则可以将脚本放入模板中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM