gpt4 book ai didi

python - Bokeh:显示用户输入的文本

转载 作者:行者123 更新时间:2023-12-02 00:13:27 25 4
gpt4 key购买 nike

我正在尝试弄清楚如何使用 Bokeh 显示用户的输入。示例代码如下。任何指示将不胜感激。

谢谢

from bokeh.layouts import widgetbox
from bokeh.models import CustomJS, TextInput, Paragraph
from bokeh.plotting import output_file, show

# SAVE
output_file('Sample_Application.html',mode='inline',root_dir=None)

# PREP DATA
welcome_message = 'You have selected: (none)'

# CALLBACKS
def callback_print(source=None, window=None):
user_input = str(cb_obj.value)
welcome_message = 'You have selected: ' + user_input
source.trigger('change')

# TAKE ONLY OUTPUT
text_banner = Paragraph(text=welcome_message, width=200, height=100)

# USER INTERACTIONS
text_input = TextInput(value="", title="Enter row number:",
callback=CustomJS.from_py_func(callback_print))

# LAYOUT
widg = widgetbox(text_input, text_banner)
show(widg)

最佳答案

有几个问题,您需要实际将文本横幅对象传递到 python 回调中,并将文本属性更新为新字符串。

当前您正在传递未定义的“source”并试图触发更改。通常,当您更改源数据并将其更新为显示在表格或绘图等上时,您会执行此操作...

包含在必要的修复下面

from bokeh.layouts import widgetbox
from bokeh.models import CustomJS, TextInput, Paragraph
from bokeh.plotting import output_file, show

# SAVE
output_file('Sample_Application.html',mode='inline',root_dir=None)

# PREP DATA
welcome_message = 'You have selected: (none)'

# TAKE ONLY OUTPUT
text_banner = Paragraph(text=welcome_message, width=200, height=100)

# CALLBACKS
def callback_print(text_banner=text_banner):
user_input = str(cb_obj.value)
welcome_message = 'You have selected: ' + user_input
text_banner.text = welcome_message

# USER INTERACTIONS
text_input = TextInput(value="", title="Enter row number:",
callback=CustomJS.from_py_func(callback_print))

# LAYOUT
widg = widgetbox(text_input, text_banner)
show(widg)

关于python - Bokeh:显示用户输入的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44101905/

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