[英]Bokeh div widget, change the text by pressing a button
我想要一個散景按鈕來更改 div 小部件中的文本。
我發現了類似的東西:
https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/
我試圖使其適合我的情況,因為鏈接中顯示的示例旨在更改按鈕本身的文本:
from bokeh.models import CustomJS
from bokeh.layouts import row, column
from bokeh.models.widgets import Div, Button
op="FirstText"
Output= Div(text="""<font size="4">""" + op + """</font>""", width=200, height=20)
ChangeTextScript = """
o1="NewText";
//location.reload();
"""
ResponseButton = Button(label="ChangeText",callback=CustomJS(args={'o1':op},code=ChangeTextScript))
layout=(
column(
ResponseButton,
Output
)
)
output_file("ChangeText.html", title="NewText")
show(layout)
按鈕和“FirstText”正在顯示,但單擊按鈕不會更改文本。 我已經發現java腳本是通過在java腳本中添加當前注釋行來觸發的(當我點擊按鈕時頁面會刷新)。
我還認為我可以使用用於刷新圖表的“ ColumnDataSource
”,但 Div 不支持“ source=...
”。
您需要將 Div 小部件本身作為回調的參數傳遞並更新其文本屬性:
ChangeTextScript = """
o1.text="<font size='4'>"+"NewText"+"</font>";
"""
ResponseButton = Button(label="ChangeText",callback=CustomJS(args={'o1':Output},code=ChangeTextScript))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.