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 on the post. Please feel free to leave a comment if you have any questions.
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
This will give you the EnpointIP your Internet is running on. The copy that IP & paste it into the Friendly Reminder page.
Then you should be directed into your streamlit web app page.
This is a great way to test your web app before actual deployment. I hope that helps
Hi JavierF,
you need to have all the function definitions that are necessary for your streamlit inside your app.py script.
(you can also define them outside the script, but in that case you need to import your module where the function is defined into the app.py)
Hope that works for you, have a great day
I have been using this solution for the past days without any issues. But today it is not working anymore. You click on the url and it remains loading forever… I tried several browsers, and installed previous versions of streamlit.
it worked before but I do not know why it does not work anymore. I have tried different browsers and it always showed loading and finally, it broke.
If anyone could give some advice or suggestions, thanks a lot.
thanks soooo much for posting this. I’ve been trying to figure this out for a hot minute.
Hello there 👋🏻
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.