我在Python包文档的Webside上使用了examples之一,将一个DateSlider小部件添加到我的bokeh web应用程序中。我的目标是创建一个DateSlider,其开始日期为2017年10月10日,结束日期为2017年10月16日,步骤等于一天。在更改DateSlider值时,我希望获得在windows shell中打印的新值(以日期格式)。相反,我得到了OSError 22。
我在Windows shell上使用命令&#34运行以下脚本:散景服务try_dateslider.py --show":
from bokeh.models.widgets import DateSlider
from bokeh.plotting import curdoc
from datetime import date
def callback(attrname, old, new):
print ("yeeeah", slider.value)
slider = DateSlider(start=date(2017, 10, 10), end=date(2017, 10, 17),
value=date(2017, 10, 17), step=1, title="Stuff")
slider.on_change('value', callback)
curdoc().add_root(slider)
小部件按预期显示在output中。但是,当我移动滑块时,我得到了Windows shell中的OSError 22。以下是shell的完整输出:
PS C:\Users\bokeh_graphs> bokeh serve try_dateslider.py --show
2017-10-24 09:07:01,624 Starting Bokeh server version 0.12.9 (running on Tornado 4.5.2)
2017-10-24 09:07:01,629 Bokeh app running at: http://localhost:5006/try_dateslider
2017-10-24 09:07:01,629 Starting Bokeh server with process id: 13764
2017-10-24 09:07:02,033 200 GET /try_dateslider (::1) 291.20ms
2017-10-24 09:07:02,358 101 GET /try_dateslider/ws?bokeh-protocol-version=1.0&
bokeh-session-id=pj6DRIQHoty4sWtH5fFHRvvWEsAutoUeTHpuPXaWvDyj (::1) 1.00ms
2017-10-24 09:07:02,358 WebSocket connection opened
2017-10-24 09:07:02,361 ServerConnection created
2017-10-24 09:07:08,478 error handling message Message 'PATCH-DOC' (revision 1):
OSError(22, 'Invalid argument')
我还尝试使用CustomJS回调创建相同的DateSlider小部件,该回调允许在webapplication中指定回调策略和DateSlider值的格式。这次我不希望在更改DateSlider值时在shell中打印新值。我再次使用"散景服务try_dateslider.py --show"命令在windows shell上运行以下脚本:
from bokeh.models.widgets import DateSlider
from bokeh.plotting import curdoc
from datetime import date
from bokeh.models import CustomJS
callback = CustomJS(code="""
var rel_date = slider.value;
""")
slider = DateSlider(title='Date of Calculation:', value=date(2017, 10, 17),
start=date(2017, 10, 10), end=date(2017, 10, 17), step=1,
callback_policy='mouseup', format="%Y-%m-%d %H:%M")
rel_date = slider.value
slider.js_on_change('value', callback)
# Print the relevant date to check what value the 'slider.value' returns. I do not expect
# to get the rel_date value printed in callback anymore
print ("the relevant date is ", rel_date)
curdoc().add_root(slider)
小部件按预期显示在output #2中。 Here是滑块移动后输出的示例。 DateSlider小部件定义中的step = 1似乎不等于一天。在Windows shell中,我得到与之前相同的错误消息。这是windows shell的完整输出:
PS C:\Users\bokeh_graphs> bokeh serve try_dateslider.py --show
2017-10-24 09:31:48,033 Starting Bokeh server version 0.12.9 (running on Tornado 4.5.2)
2017-10-24 09:31:48,037 Bokeh app running at: http://localhost:5006/try_dateslider
2017-10-24 09:31:48,037 Starting Bokeh server with process id: 11600
the relevant date is 2017-10-17
2017-10-24 09:31:48,465 200 GET /try_dateslider (::1) 316.47ms
2017-10-24 09:31:48,880 101 GET /try_dateslider/ws?bokeh-protocol-
version=1.0&bokeh-session-id=8XFPdCZRCoDvOFZUVGwvP5TnLpKOvouNrOAlRUHux7Ar (::1) 1.02ms
2017-10-24 09:31:48,880 WebSocket connection opened
2017-10-24 09:31:48,883 ServerConnection created
2017-10-24 09:38:28,572 error handling message Message 'PATCH-DOC' (revision 1):
OSError(22, 'Invalid argument')
我使用的是Python 3.6.3(64位)和散景0.12.9。以下可能是相关的,但没有解决我的问题: