有没有在Google Colab上运行Web应用程序的一般方法? [英] Is there a general way to run Web Applications on Google Colab?
问题描述
我想在Google colab中开发Web应用程序.唯一的问题是,您需要将浏览器连接到本地主机才能查看该Web应用程序,但是Google colab在笔记本中没有浏览器.
I would like to develop web apps in Google colab. The only issue is that you need a browser connected to local host to view the web app, but Google colab doesn't have a browser inside the notebook.
但是似乎有一些解决方法.例如,run_with_ngrok是用于在colab/jupyter笔记本中运行flaks应用程序的库
But it seems that there are ways around this. For example run_with_ngrok is a library for running flaks apps in colab/jupyter notebooks
https://github.com/gstaff/flask- ngrok#inside-jupyter--可乐笔记本
使用它时,它会提供一个随机地址在http://.ngrok.io上运行"
When you use it, it gives a random address , "Running on http://.ngrok.io"
以某种方式,在Google colab上运行的Web应用程序正在该地址上运行.
And somehow the webapp that's running on Google colab is running on that address.
这是Flask应用程序的绝佳解决方案,但我希望在Google Colab上运行Web应用程序,而不仅仅是Flask.在colab/jupyter笔记本中有运行Webapp的通用方法吗?
This is a great solution for Flask apps, but I am looking to run webapps in general on Google Colab, not just Flask ones. Is there a general method for running webapps in colab/jupyter notebooks?
推荐答案
在此处找到答案
### 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'])"
然后在端口8050上启动您的Web应用程序
Then launch your webapp on port 8050
这篇关于有没有在Google Colab上运行Web应用程序的一般方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!