Skip to content

Commit

Permalink
Create guide_streamlit.rst (#1847)
Browse files Browse the repository at this point in the history
* Create guide_streamlit.rst

* dropped non-root dir as requested

* Update guide_streamlit.rst

* [Streamlit] rewrite according to our template, fix links and layout

---------

Co-authored-by: Moritz <[email protected]>
  • Loading branch information
entorb and nichtmax authored Jan 22, 2025
1 parent 22ad356 commit 5b9b01d
Showing 1 changed file with 129 additions and 0 deletions.
129 changes: 129 additions & 0 deletions source/guide_streamlit.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
.. highlight:: console

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

.. tag:: lang-python
.. tag:: streamlit
.. tag:: web
.. tag:: audience-developers

#########
Streamlit
#########

.. tag_list::

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

* :manual:`Python <lang-python>` and its package manager pip
* :manual:`Supervisord <daemons-supervisord>` to set up your service

License
=======

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

Prerequisites
=============

Your URL needs to be setup:

.. include:: includes/web-domain-list.rst

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

Installation
============

Install the latest Streamlit version.

.. code-block:: console
[isabell@stardust ~]$ pip3.11 install --user streamlit
[isabell@stardust ~]$
Create Project
--------------

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

.. code-block:: console
[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``

.. code-block::
[browser]
gatherUsageStats = false
[server]
headless = true
port = 8501
baseUrlPath = ""
See Streamlit `configuration documentation`_ for more information.

Example App
===========

Create ``~/mysiteproject/app.py``

.. code-block:: python
import streamlit as st
st.title("Test")
Add Web Backend
===============

.. note:: Streamlit is running on port 8501.

.. include:: includes/web-backend.rst

Setup Service
=============

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

.. code-block:: ini
:emphasize-lines: 2,3
[program:mysiteproject]
directory=%(ENV_HOME)s/mysiteproject
command=streamlit run app.py
After creating the configuration, tell :manual:`supervisord <daemons-supervisord>` to refresh its configuration and start the service.

.. include:: includes/supervisord.rst

Configure Web Backend
---------------------

.. note:: Streamlit is running on port 8501.

.. include:: includes/web-backend.rst

Your backend should now point to the service.

.. _Streamlit: https://docs.streamlit.io/
.. _terms of use: https://streamlit.io/terms-of-use
.. _configuration documentation: https://docs.streamlit.io/develop/api-reference/configuration/config.toml

----

Tested with Streamlit 1.40.2, Python 3.11, Uberspace 7.16

.. author_list::

0 comments on commit 5b9b01d

Please sign in to comment.