在Google Colab Noteb中启动Dash应用程序

2024-04-28 21:43:23 发布

您现在位置:Python中文网/ 问答频道 /正文

如何从googlecolab(https://colab.research.google.com)启动Dash应用程序(http://dash.plot.ly)?在


Tags: httpscom应用程序httpplotgooglelycolab
1条回答
网友
1楼 · 发布于 2024-04-28 21:43:23

据我所知,目前还没有直接的方法来做到这一点。在

在下面找到一个类似于设置Tensorboard(https://www.dlology.com/blog/quick-guide-to-run-tensorboard-in-google-colab/)的解决方法。在

从设置此解决方案所需的所有内容的代码单元开始:

# How to run a Dash app in Google Colab

## Requirements

### Install ngrok
!wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
!unzip ngrok-stable-linux-amd64.zip

### Run ngrok to tunnel Dash app port 8050 to the outside world. 
### This command runs in the background.
get_ipython().system_raw('./ngrok http 8050 &')

### Get the public URL where you can access the Dash app. Copy this URL.
! curl -s http://localhost:4040/api/tunnels | python3 -c \
    "import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'])"

### Install Dash
!pip install dash==0.31.1  # The core dash backend
!pip install dash-html-components==0.13.2  # HTML components
!pip install dash-core-components==0.39.0  # Supercharged components
!pip install dash-table==3.1.7  # Interactive DataTable component (new!)

使用仪表板应用程序添加另一个代码单元格:

^{pr2}$

在最后一个代码单元格中,你可以启动你的Dash应用程序(在你停止执行,从而停止你的Dash应用程序之前,这个单元格一直很忙)。在

### Run Dash app
!python my_app1.py

要访问Dash应用程序,请复制并粘贴ngrok.io-上面的URL指向新的浏览器选项卡(不是127.0.0.1:8050),然后等待几秒钟。在

相关问题 更多 >