Javascript Bokeh div小部件,通过按按钮更改文本
我想要一个bokeh按钮来更改div小部件中的文本 我发现了类似的东西: 我试图使其适合我的情况,因为链接中显示的示例旨在更改按钮本身的文本:Javascript Bokeh div小部件,通过按按钮更改文本,javascript,python,jupyter-notebook,bokeh,Javascript,Python,Jupyter Notebook,Bokeh,我想要一个bokeh按钮来更改div小部件中的文本 我发现了类似的东西: 我试图使其适合我的情况,因为链接中显示的示例旨在更改按钮本身的文本: 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">""
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)
来自bokeh.models导入CustomJS
从bokeh.layouts导入行、列
从bokeh.models.widgets导入Div,按钮
op=“FirstText”
输出=Div(文本=“”+op+“”,宽度=200,高度=20)
ChangeTextScript=“”
o1=“新文本”;
//location.reload();
"""
ResponseButton=Button(label=“ChangeText”,callback=CustomJS(args={'o1':op},code=ChangeTextScript))
布局=(
纵队(
响应按钮,
输出
)
)
输出文件(“ChangeText.html”,title=“NewText”)
显示(布局)
将显示按钮和“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))
ChangeTextScript=”“”
o1.text=“+”新文本“+”;
"""
ResponseButton=Button(label=“ChangeText”,callback=CustomJS(args={'o1':Output},code=ChangeTextScript))
@Seb提供了下面的答案,我还想指出邮件列表已经失效。所有旧内容都已转移到新的项目论述中,该项目的搜索性能大大提高: