Streamlit

Streamlit is a high-level Python Web framework focussing on data visualization.


Note

For this guide, you should be familiar with the basic concepts of

License

All relevant legal information can be found in the terms of use.

Prerequisites

Your URL needs to be setup:

[isabell@stardust ~]$ uberspace web domain list
isabell.uber.space
[isabell@stardust ~]$

For this guide we will use mysiteproject as the project’s name and will install it to ~/mysiteproject.

Installation

Install the latest Streamlit version.

[isabell@stardust ~]$ pip3.11 install --user streamlit
[isabell@stardust ~]$

Create Project

Create a directory for your project. We use ~/mysiteproject for this guide.

[isabell@stardust ~]$ mkdir ~/mysiteproject
[isabell@stardust ~]$ mkdir ~/mysiteproject/.streamlit
[isabell@stardust ~]$

Warning

While it does not matter how you name it and where you put it, we suggest that you do not put this directory under any path served to the web (e.g. ~/html), to avoid exposing your files.

Configuration

Create ~/mysiteproject/.streamlit/config.toml

[browser]
gatherUsageStats = false

[server]
headless = true
port = 8501
baseUrlPath = ""

See Streamlit configuration documentation for more information.

Example App

Create ~/mysiteproject/app.py

import streamlit as st
st.title("Test")

Add Web Backend

Note

Streamlit is running on port 8501.

To make the application accessible from the outside, configure a web backend:

[isabell@stardust ~]$ uberspace web backend set / --http --port <port>
Set backend for / to port <port>; please make sure something is listening!
You can always check the status of your backend using "uberspace web backend list".
[isabell@stardust ~]$

Setup Service

Create ~/etc/services.d/mysiteproject.ini with the following content:

[program:mysiteproject]
directory=%(ENV_HOME)s/mysiteproject
command=streamlit run app.py

After creating the configuration, tell supervisord to refresh its configuration and start the service.

After creating the configuration, tell supervisord to refresh its configuration and start the service:

[isabell@stardust ~]$ supervisorctl reread
SERVICE: available
[isabell@stardust ~]$ supervisorctl update
SERVICE: added process group
[isabell@stardust ~]$ supervisorctl status
SERVICE                            RUNNING   pid 26020, uptime 0:03:14
[isabell@stardust ~]$

Configure Web Backend

Note

Streamlit is running on port 8501.

To make the application accessible from the outside, configure a web backend:

[isabell@stardust ~]$ uberspace web backend set / --http --port <port>
Set backend for / to port <port>; please make sure something is listening!
You can always check the status of your backend using "uberspace web backend list".
[isabell@stardust ~]$

Your backend should now point to the service.


Tested with Streamlit 1.40.2, Python 3.11, Uberspace 7.16

Written by: Torben <https://entorb.net/contact.php?origin=UberspaceLab>