关于bokeh 0.11的困惑:获取一个用户可读的session id
Confusion about bokeh 0.11: obtain a user readable session id
bokeh 0.10 的文档还不错,有很多不错的 examples around。但是,我现在真的不知道如何告诉 bokeh 0.11 使用易于记忆的 url。我目前的尝试:
将 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')
不过,url还是有点笨拙:http://localhost:5006/?bokeh-session-id=yeah
有什么方法可以将其更改为 http://localhost:5006/yeah
?
编辑:我应该提一下,我正在传输数据。数据由 class 收集,它本身在另一个 class 中启动。结果,我不能轻易调用 bokeh serve DAQ.py
。此外,我没有定期更新功能。这取决于一些工艺条件。
这种使用Bokeh服务器的方法(有bokeh.client
)确实适合本地,个人使用。这里有对不同用例场景的有用讨论
https://docs.bokeh.org/en/latest/docs/user_guide/server.html#use-case-scenarios
如果您想创建一个其他用户可以与之交互的 "deployable app",您绝对想创建一个 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)
此处提供有关创建和部署应用程序的更多信息:
https://docs.bokeh.org/en/latest/docs/user_guide/server.html#building-bokeh-applications
此处描述了 bokeh serve
的所有命令行选项:
https://docs.bokeh.org/en/latest/docs/reference/command/subcommands/serve.html
这里有几个应用实例(带有源代码链接):
bokeh 0.10 的文档还不错,有很多不错的 examples around。但是,我现在真的不知道如何告诉 bokeh 0.11 使用易于记忆的 url。我目前的尝试:
将 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')
不过,url还是有点笨拙:http://localhost:5006/?bokeh-session-id=yeah
有什么方法可以将其更改为 http://localhost:5006/yeah
?
编辑:我应该提一下,我正在传输数据。数据由 class 收集,它本身在另一个 class 中启动。结果,我不能轻易调用 bokeh serve DAQ.py
。此外,我没有定期更新功能。这取决于一些工艺条件。
这种使用Bokeh服务器的方法(有bokeh.client
)确实适合本地,个人使用。这里有对不同用例场景的有用讨论
https://docs.bokeh.org/en/latest/docs/user_guide/server.html#use-case-scenarios
如果您想创建一个其他用户可以与之交互的 "deployable app",您绝对想创建一个 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)
此处提供有关创建和部署应用程序的更多信息:
https://docs.bokeh.org/en/latest/docs/user_guide/server.html#building-bokeh-applications
此处描述了 bokeh serve
的所有命令行选项:
https://docs.bokeh.org/en/latest/docs/reference/command/subcommands/serve.html
这里有几个应用实例(带有源代码链接):