How to Install Streamlit on Ubuntu 21.04
Introduction
Streamlit is an open-source python library designed to create custom web applications for machine learning and data science. It is one of the fastest ways to design, build, and deploy data applications. This article explains how to run a Streamlit-based web application on an Ubuntu 21.04 Server.
1. Install Prerequisites
- Deploy a Vultr Ubuntu 21.04 instance.
- Login as root
- Update the Ubuntu server.
Updating the Ubuntu server will update the pre-installed python as well. Unfortunately, the pre-installed python does not come with the pip package manager, so it needs to be installed.
To install python pip package manager, run:
# apt install python3-pip -y
Next, install Streamlit using python pip. Run:
# pip install streamlit
2. Running Streamlit on Ubuntu 21.04
When you run Streamlit on a normal SSH Session, the Streamlit process will close once you exit the SSH Session. To run Streamlit when you leave the SSH session, use tmux, a terminal multiplexer. Using a terminal multiplexer will allow you to run the Streamlit process in the background.
To create a tmux session, run:
# tmux new -s StreamlitSession
You can change StreamlitSession
to any session name you prefer. Please see How to Install and Use Tmux for more information.
Option 1: Run Streamlit on the Default Port
Once you are on the Terminal Multiplexer, you can now run your main python script. Make sure that your python script is in the /root/ directory, then run:
# streamlit run main.py
Change main.py
to your python script file name.
When you run Streamlit for the first time, you will be prompted to enter your email address. If you want to receive Streamlit updates, kindly enter your email address, or you can press Enter to skip it.
To view your deployed web application, visit your server's IP address at Streamlit's default port, 8501. For example: http://192.0.2.12:8501
Option 2: Run Streamlit on the HTTP Port
To deploy your web application on HTTP Port (80), run:
# streamlit run main.py --server.port 80
Change main.py
to your python script file name.
To view your deployed web application, visit your server's IP address. For example: http://192.0.2.12
Troubleshooting
To learn more about Streamlit, please visit the Streamlit documentation.