我是使用Python的bokeh绘图工具和小部件的初学者。在下面的代码中,我试图将图形的标题更改为TextInput框的值。但是,虽然在输入文本和未聚焦时出现该框,但没有任何变化。是什么导致此问题,我该怎么解决?
p=figure(
height=400,
x_axis_type='datetime',
title=(company+' ('+tickerstring+') ')
)
thedates = np.array(stockdates, dtype=np.datetime64)
source = ColumnDataSource(data=dict(
x=thedates,
y=stockcloseprices
))
p.line('x', 'y', source=source)
p.grid.grid_line_color="white"
p.xaxis.axis_label = 'Date'
p.yaxis.axis_label = 'Price'
p.add_tools(HoverTool(
tooltips=[
("Date", "@x{%F}"),
('Close',"@y")
],
formatters={
'x':'datetime', # use 'datetime' formatter for 'date' field
},
mode='vline'
))
def update_title(attrname, old, new):
p.title = text.value
div = Div(text='<br><b> Key Points </b><br><br>'+percentagechange+'<br><br>'+performance,
width=200, height=100)
text = TextInput(value='Name', title="Enter Ticker Here:")
text.on_change('value', update_title)
grid = gridplot([p, div, text], ncols=2, plot_width=570, plot_height=400)
show(grid)
答案 0 :(得分:1)
通过使用show
,您将创建一个独立的HTML文档作为输出。由于浏览器无法运行python代码,因此无法运行真正的python回调。运行真实的回调需要与持久的Python进程建立连接。那就是散景服务器。只能在bokeh服务器应用程序中使用真实的python回调(即与on_change
一起使用(这是bokeh服务器的用途,因为它是运行真实的python回调的东西)。请参阅:
https://bokeh.pydata.org/en/latest/docs/user_guide/server.html