To create a Streamlit application in Python and host it on your Ubuntu server at [your IP address]/LR, follow these steps:
- Install Streamlit and other required packages:
First, you need to install Python and pip on your Ubuntu server if you haven't already. You can follow the instructions in the official documentation: https://packaging.python.org/guides/installing-using-linux/
Once you have Python and pip installed, create a virtual environment and activate it:
python3 -m venv streamlit_env
source streamlit_env/bin/activate
Now, install Streamlit and other required packages:
pip install streamlit pandas numpy
- Create your Streamlit application:
Create a new Python script (e.g., app.py) and write your Streamlit application:
# app.py
import streamlit as st
import pandas as pd
import numpy as np
st.title('My Streamlit Application')
st.write('Hello, World!')
# Add more Streamlit code as needed
- Set up a basic web server:
Install a simple web server like Flask or Gunicorn. In this example, we will use Gunicorn:
pip install gunicorn
- Create a Gunicorn configuration file (
gunicorn.conf.py) to specify the path to your Streamlit application:
# gunicorn.conf.py
import os
chdir = '/path/to/your/streamlit/app'
workers = 3
bind = '[your IP address]:8080'
Replace /path/to/your/streamlit/app with the actual path to the directory containing app.py.
- Create a startup script (
start_streamlit.sh) to start the Streamlit application:
#!/bin/bash
# Start Gunicorn
gunicorn --config gunicorn.conf.py app:app
Make the script executable:
chmod +x start_streamlit.sh
- Set up your firewall:
Allow incoming traffic on port 8080 (or the port you specified in the Gunicorn configuration file) using UFW:
sudo ufw allow 8080/tcp
- Start your Streamlit application:
Run the startup script:
./start_streamlit.sh
- Access your Streamlit application:
Visit [your IP address]:8080/LR in your web browser to access the Streamlit application.
Note: Make sure to replace [your IP address] with the actual IP address of your Ubuntu server.