Bokeh cursession()AttributeError:NoneType对象没有属性' store_objects'

时间:2015-01-23 19:06:46

标签: python python-2.7 bokeh

我正在尝试在IPython笔记本中设置一个简单的流式散景示例,但最后一步遇到了一些麻烦。我以http://bokeh.pydata.org/en/latest/docs/user_guide/examples.html#id1https://github.com/awesomebytes/bokeh_ros/blob/master/scripts/multiple_updateable_plots.py为例。作为参考,我在Windows 7上使用Anaconda的散景0.7.1。在我的笔记本中:

from bokeh.models import ColumnDataSource, Plot
from bokeh.plotting import *
from bokeh.models.renderers import GlyphRenderer

outout_notebook()
source = make_source()  #ColumnDataSource type
plot = figure(title = 'test',
        tools = 'pan, wheel_zoom, select, reset',
        x_range = x_range,
        plot_width = 700, plot_height = 600)

colors = ['red', 'blue', 'orange', 'green', 'purple', 'yellow', 'pink', 'red', 'blue', 'orange', 'green', 'purple', 'yellow', 'pink']
colorcounter = 0

for x in symbols:
    if x!= ' ':
        plot.line(x = 'time', 
            y = x, 
            legend = x, 
            color = colors[colorcounter], 
            weight = '200px',
            source = source)
        colorcounter += 1

show()
renderer = [r for r in curplot().renderers if isinstance(r, GlyphRenderer)][0]
ds = renderer.data_source

此时,我的笔记本中出现了正确的情节。为了启用流媒体,我接下来:

while True:
    df = make_source()
    ds.data = df.data
    ds._dirty = True
    cursession().store_objects(ds)
    time.sleep(10)

但我一直收到消息

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-d4967016d7d3> in <module>()
      3     ds.data = df.data
      4     ds._dirty = True
----> 5     cursession().store_objects(ds)
      6     time.sleep(10)

AttributeError: 'NoneType' object has no attribute 'store_objects'

通常,当对象尚未“实例化”时会发生这种情况,但我不明白在这种情况下会出现什么问题。我在后台运行bokeh-server,与我的笔记本位于同一目录中。如何实例化cursession(),以便我可以在笔记本中流式传输?我是否必须输出到服务器?

1 个答案:

答案 0 :(得分:0)

您需要将一个URL作为output_notebook的参数传递给散景服务器,以便创建会话。