简体   繁体   English

Bokeh div 小部件,通过按下按钮更改文本

[英]Bokeh div widget, change the text by pressing a button

I want a bokeh button to change the text in a div widget.我想要一个散景按钮来更改 div 小部件中的文本。

I found something similar:我发现了类似的东西:

https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/ https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/

I tried to make this fit for my situation, as the example shown in the link was meant to change the text of the button itself:我试图使其适合我的情况,因为链接中显示的示例旨在更改按钮本身的文本:

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)

The button and the "FirstText" are getting displayed, but clicking the button does not change the text.按钮和“FirstText”正在显示,但单击按钮不会更改文本。 I already found out that the java script is triggered by adding the currently commented line in java script (the page is refreshed when I clicked the button).我已经发现java脚本是通过在java脚本中添加当前注释行来触发的(当我点击按钮时页面会刷新)。

I also thought that I could use a " ColumnDataSource " which is used for refreshing Diagrams, but Div does not support " source=... ".我还认为我可以使用用于刷新图表的“ ColumnDataSource ”,但 Div 不支持“ source=... ”。

You need to pass the Div widget itself as argument for the callback and update its text property:您需要将 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.

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