Diazonic Labs

Feb 15, 2021

2 min read

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.

1st Cell

!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

--quiet is used to give less logs in the output section.

2nd Cell

%%writefile app.py
import streamlit as st
st.title(‘Diazonic Labs’)

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.

3rd Cell

!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.