python - 在本地网络上运行 Bokeh 服务器

标签 python bokeh

我有一个名为 app.py 的简单 Bokeh 应用程序,如下所示:

### contents of app.py

from bokeh.client import push_session
from bokeh.embed import server_document
from bokeh.plotting import figure, curdoc

plot = figure()
plot.circle([1,2], [3,4])

doc = curdoc()
doc.add_root(plot)

我可以使用以下命令运行此应用程序:

bokeh serve app.py

然后我可以通过网络浏览器访问该图:http://localhost:5006/app。

但是,我希望我的专用网络上的所有设备都可以使用其网络浏览器使用该图。我该怎么做?

我发现以下命令作为建议的解决方案,但它不起作用,因为它指出我的 IP 地址不可用。

bokeh serve --allow-websocket-origin='ip address':'port number' my_app.py --port 'port number'

干杯!

最佳答案

以下命令适用于我的本地网络,使用 Bokeh v1.0.4。首先启动 IP:PORT = 192.168.1.208:5001 上的 Bokeh 服务器。这将打开一个显示该应用程序的新浏览器选项卡。您可以看到远程客户端正在 IP:POST = 192.168.1.201(另一台计算机)上进行连接,该图已成功显示在远程计算机上的浏览器中。

bokeh serve --address 192.168.1.208 --port 5001 --allow-websocket-origin=192.168.1.201:5001 --allow-websocket-origin=192.168.1.208:5001 --show simple_app.py

2019-03-07 20:01:54,289 Starting Bokeh server version 1.0.4 (running on Tornado 4.5.3)
2019-03-07 20:01:54,294 Bokeh app running at: http://192.168.1.208:5001/simple_app
2019-03-07 20:01:54,295 Starting Bokeh server with process id: 49031
2019-03-07 20:01:54,581 200 GET /simple_app (192.168.1.208) 135.34ms
2019-03-07 20:01:54,694 101 GET /simple_app/ws?bokeh-protocol-version=1.0&bokeh-session-id=Ino2U2RYLAJ9LQXIGgNmPXnRyZNJHZQcTEEfsX0bM3f9 (192.168.1.208) 0.82ms
2019-03-07 20:01:54,694 WebSocket connection opened
2019-03-07 20:01:54,695 ServerConnection created
2019-03-07 20:02:03,208 200 GET /simple_app (192.168.1.201) 24.19ms
2019-03-07 20:02:55,503 200 GET /simple_app (192.168.1.201) 24.17ms
2019-03-07 20:02:55,617 200 GET /static/css/bokeh.min.css?v=4c253f78f16b7d5d0c9d1df8062c7f4c (192.168.1.201) 7.32ms
2019-03-07 20:02:55,618 200 GET /static/css/bokeh-widgets.min.css?v=6f280acb818327130a8c244ce05fd10d (192.168.1.201) 0.64ms
2019-03-07 20:02:55,618 200 GET /static/css/bokeh-tables.min.css?v=86c18b0b1fd30cdbc124e60cb9452e73 (192.168.1.201) 0.59ms
2019-03-07 20:02:55,743 200 GET /static/js/bokeh-widgets.min.js?v=68fceb4be2f3d6410ff2d7704c8b87cf (192.168.1.201) 1.01ms
2019-03-07 20:02:55,890 200 GET /static/js/bokeh-gl.min.js?v=70e18d8dcea09947c12764bf85ec76a0 (192.168.1.201) 1.09ms
2019-03-07 20:02:56,222 200 GET /static/js/bokeh-tables.min.js?v=02bdadb2c698bc2855a4d4a69c163821 (192.168.1.201) 478.59ms
2019-03-07 20:02:56,636 200 GET /static/js/bokeh.min.js?v=afab3eba5b3a72c05610143940e03c8e (192.168.1.201) 896.20ms
2019-03-07 20:02:58,134 404 GET /favicon.ico (192.168.1.201) 0.55ms
2019-03-07 20:02:58,149 101 GET /simple_app/ws?bokeh-protocol-version=1.0&bokeh-session-id=2CR07bJEIWPwWj07dPH3SSrou74mWgOwetucvIPuD3sk (192.168.1.201) 0.81ms
2019-03-07 20:02:58,149 WebSocket connection opened
2019-03-07 20:02:58,150 ServerConnection created

关于python - 在本地网络上运行 Bokeh 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55049175/

相关文章:

python - numpy 在数组中的重复值中选择固定数量的值

python - 使用 Google Gmail API 进行桌面应用程序

javascript - 我如何浏览器化 BokehJS

python - 为什么 Bokeh 不在这里生成额外的 y 范围?

python - hvplot.heatmap 与 Pandas 数据框 : How to specify value dimensions?

python - 带有 python 2 的 Ubuntu

Python只读取excel单元格中的公式

python - Holoviews:图框尺寸和纵横比

python - 将 BeautifulSoup 对象转换为列表以提取数据

python - 无法从 'Scatter' 导入名称 'bokeh.plotting'