关于散景0.11的困惑:获得用户可读的会话ID

时间:2016-02-15 22:32:30

标签: python bokeh

散景0.10的文档没问题,并且有很多好examples around。但是,我现在不知道如何告诉散景0.11使用容易记住的网址。我目前的尝试:

将numpy导入为np     进口时间

from bokeh.client import push_session
from bokeh.plotting import figure, curdoc, output_server

x = np.random.rand(10)
y = np.random.rand(10)

p = figure()
r2 = p.line(x, y, color="navy", line_width=4)
# open a session to keep our local document in sync with server
session = push_session(curdoc())
session.show() # open the document in a browser
time.sleep(2)
while True:
    x = np.random.rand(10)
    y = np.random.rand(10)
    r2.data_source.data["y"] = y
    r2.data_source.data["x"] = x
    time.sleep(2)

来自Docs

push_session(curdoc(),session_id = 'yeah')

然而,网址仍然有点笨拙:http://localhost:5006/?bokeh-session-id=yeah 有没有办法将其更改为http://localhost:5006/yeah

编辑:我应该提一下,我是流数据。数据由一个类收集,该类本身在另一个类中启动。因此,我无法轻易拨打bokeh serve DAQ.py。此外,我没有定期更新功能。这取决于一些工艺条件。

1 个答案:

答案 0 :(得分:7)

这种使用Bokeh服务器(带bokeh.client)的方法非常适合本地,个人使用。这里有一个关于不同用例场景的有用讨论

http://bokeh.pydata.org/en/latest/docs/user_guide/server.html#use-case-scenarios

如果您想创建其他用户可以与之交互的“可部署应用程序”,您绝对想要创建一个Bokeh应用程序(实际上更简单)。基本思想是创建一个使用bokeh serve命令运行的脚本,例如

bokeh serve myapp.py --show 

默认情况下,这是http://localhost:5006/myapp。您上面的代码将简化为:

import numpy as np
from bokeh.plotting import figure, curdoc 

x = np.random.rand(10)
y = np.random.rand(10)

p = figure()
r2 = p.line(x, y, color="navy", line_width=4)

# define a callback to update the data
def update():
    x = np.random.rand(10)
    y = np.random.rand(10)

    # important to update all data "at once"
    r2.data_source.data = dict(x=x, y=y)

# run the callback to update the data every 2000 ms
curdoc().add_periodic_callback(update, 2000)

有关创建和部署应用程序的更多信息,请访问:

http://bokeh.pydata.org/en/latest/docs/user_guide/server.html#building-bokeh-applications

此处描述bokeh serve的所有命令行选项:

http://bokeh.pydata.org/en/latest/docs/user_guide/cli.html#module-bokeh.command.subcommands.serve

以下是几个应用程序的实例(包含指向源代码的链接):

http://demo.bokehplots.com