Running Streamlit from Google Colab
Streamlit is a Python library for building Web Apps. System’s configuration and compatibility plays a handy role in running the Web App locally on your computer.
Google Colab comes to the rescue here . We can use Colab without worrying about the system configuration.
I have divided the Colab notebook into 3 cells each indicating specific task.
!pip install streamlit --quiet
!pip install pyngrok==4.1.1 --quiet
from pyngrok import ngrok
Installing Streamlit for creating simple web Apps.
Installing Pyngrok which is python wrapper for Ngrok Server. Ngrok is a powerful solution for providing secure tunnels from your local system to the public.
More on ngrok platform
ngrok - secure introspectable tunnels to localhost
ngrok secure introspectable tunnels to localhost webhook development tool and debugging tool
--quiet is used to give less logs in the output section.
import streamlit as st
we use the magic command %%writefile to write the contents of the cell to a file.
I have just imported a simple Hello World kind of program displaying a text.
!nohup streamlit run app.py &
url = ngrok.connect(port = ‘8501’)
Use the command line statement streamlit run app.py to run the Web App.
Append it with nohup command so that thee output is stored in nohup file
Also put ‘&’ towards the end. This helps a streamlit file run in the background.
Next connect to ngrok with default port of 8501 and get the public URL
NOTE: Run the cells in order .
Once you get the public URL, make changes only in the 2nd cell and execute it. Dont execute cells 1 and 3 after you get public URL. This might led to error.