How to Launch Streamlit App from Google Colab Notebook

Hello everyone!

I recently came across a way to launch a streamlit app from a Google Colab Notebook and wanted to share this with you.

Google Colab is a free cloud service for machine learning and artificial intelligence made available by Google. It provides a Jupyter notebook environment which can be used to code, debug, analyze data and more. It is a great platform for quickly prototyping and experimenting, making development much faster and efficient.

Run a Streamlit App on Google Colab Notebook
Launch google Colab, and create a new Notebook https://colab.research.google.com/.

Install Streamlit library

!pip install -q streamlit

Create a streamlit app example

%%writefile app.py

import streamlit as st

st.write('Hello, *World!* :sunglasses:')

Install localtunnel to serve the Streamlit app

!npm install localtunnel

Run the Streamlit app in the background

!streamlit run app.py &>/content/logs.txt &

Expose the Streamlit app on port 8501
Then just click in the url showed.

!npx localtunnel --port 8501

If you find this helpful Select :heart: on the post. Please feel free to leave a comment if you have any questions.

Thank you! :wave:

2 Likes


I get this everytime. What should i do now?

1 Like


3 Likes

Here is a Google Colab Example with Streamlit:

In this Colab Example there is a code line to create a log.txt file: !streamlit run /content/app.py &>/content/logs.txt &
Within the log.txt file there are the URLs which can be used for creating the tunel. Copy only the External URL IP without the Port in the Endpoint IP field as discribed above.
Hope this is helpful :wink:

1 Like

very good