从本地网络上的其他计算机访问面板仪表板

Access to panel dashboard from other computer on local network

我正在 Holoviews 中构建一个仪表板,并尝试使用 Jupyter notebook 中的 panel.serve() 为其提供服务。它在我的本地计算机上运行良好,但我需要与公司网络中的其他计算机共享它,以便人们可以实际使用它。由于隐私问题,我不能将它部署到 Heroku 或类似的东西。 这是示例代码:

import panel as pn
pn.extension()
dashboard_title = pn.panel('## Test Dashboard')
dashboard_footlote = pn.panel('Test Test Test')
dash = pn.Column(dashboard_title, dashboard_footlote)
dash.servable(title="Claims Dashboard")
pn.serve(dash)

当我在 Jupyter notebook 中 运行 它时,它会打开一个新的浏览器 window 和其中的仪表板。我尝试通过在地址栏中键入 http://10.80.60.31:60840/ 从另一台计算机访问相同的仪表板。但这并没有显示任何东西。在 Jupyter 单元格中,我收到以下错误:

ERROR:bokeh.server.views.ws:Refusing websocket connection from Origin 'http://10.80.40.41:60840';
use --allow-websocket-origin=10.80.40.41:60840 or set BOKEH_ALLOW_WS_ORIGIN=10.80.40.41:60840 to permit this; currently we allow origins {'localhost:60840'}

我尝试将代码的最后一行更改为以下内容:

pn.serve(dash, websocket_origin=['10.80.60.31:60840','localhost:60840'])

但是由于端口更改,它甚至在本地也不起作用。它给我一个错误:

ERROR:bokeh.server.views.ws:Refusing websocket connection from Origin 'http://localhost:58370';
use --allow-websocket-origin=localhost:58370 or set BOKEH_ALLOW_WS_ORIGIN=localhost:58370 to permit this; currently we allow origins {'localhost:60840', '10.80.60.31:60840'}

如果我尝试像这样分配特定端口:

pn.serve(dash, port = 60840, websocket_origin=['10.80.60.31:60840','localhost:60840'])

它甚至没有开始说:

OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted

解决方案可能很简单,但我对所有网络知识知之甚少,甚至不知道要做什么 google。

如果你能指导我如何让它工作,我将不胜感激。

我在 .py 文件中使用 pn.serveable(dash),然后单独启动 panel serve --port 8086 file.py,但我认为这与您所做的工作类似。典型的“陷阱”是您需要确保您使用的任何端口都没有被您的网络配置防火墙保护,以便其他计算机可以访问它。您可能需要在计算机的防火墙规则中添加例外以打开特定端口。您可以使用该端口上的任何程序(Web 服务器、ssh 客户端、telnet 客户端等)进行测试; Panel 的服务器在这方面没有任何特殊要求。 https://docs.bokeh.org/en/latest/docs/user_guide/server.html#deployment-scenarios 中有很多详细信息,但是在公司环境中,您必须与 IT 部门一起解决配置系统不阻止特定端口的问题。

我有一个建议。尝试将“*”添加到 Origins

列表
pn.serve(dash, port=80, websocket_origin=['*'])

我试过你的代码,它对我有效。