My goals in this talk:
Streamlit is a Python library for building and sharing data applications.
A data application is a web-based application intended to display, analyze, or visualize data. This data may come from a database, set of files, API, or other data source.
Data applications in Streamlit allow for some level of interaction but Streamlit is not a replacement for general-purpose web development. There are some simplistic mechanisms in place for handling session state and user input, but you may find a more comprehensive web framework like Django to fit when you need to accept form input or display a variety of content-driven, templated pages.
One very helpful preparatory action before installing Streamlit is to create a virtual environment.
Virtual environments help you isolate project dependencies and prevent scenarios where different projects have different and conflicting versions of dependency packages.
Run this in the root directory where you'll keep your Streamlit code.
Then, activate your virtual environment.
A virtual environment will be active until you close your terminal or manually deactivate it. To deactivate the virtual environment and return to your main Python setup:
Streamlit also installs the pyarrow
package.
Streamlit will then kick off a web server that will host your Python file, usually on port 8501.
The Streamlit gallery has curated applications you can use as inspiration.
Daniel Lewis has a nice cheat sheet Streamlit application.
The best way to get a handle on Streamlit is to build applications in the framework. Let's look at the process to build up a full-featured data application!
Streamlit has some basic theming options available. You can try them out in the browser or create a config file in ./.streamlit/config.toml
There are a few ways to host Streamlit applications.
Self-hosting Streamlit requires a web server proxy like NGINX. This proxy will allow you to forward inbound calls to your running Streamlit process.
On Linux, you can run your Streamlit app as a background service using systemd
. To do so, you will need a config file in /.config/systemd/user/
.
Once you have a config file, you can enable and activate the service:
One common method for deploying Streamlit apps is to host them in Docker containers. A sample Dockerfile could look like:
Once you have a Dockerfile, you can build the image and run it. The following command will create a Docker image called "streamlit" based on your current directory's solution, including Dockerfile. It will then run an instance of the container image on port 8501.
Streamlit offers a free service for hosting your applications, called Streamlit Community Cloud. This works well for demo apps or community tools, and there are some limited capabilities for restricting access to apps.
If you are a Snowflake customer, you can host Streamlit applications in Snowflake, unless you are using AWS PrivateLink or Azure Private Link.
There are some product limitations versus self-hosting, but this is a good option for Snowflake customers who want to keep their data close to their data warehouse.
Over the course of this talk, we have gained an understanding of what Streamlit is, how quickly you can build a Streamlit application, and various options available for hosting Streamlit applications.
To learn more, go here:
https://csmore.info/on/streamlit
And for help, contact me:
feasel@catallaxyservices.com | @feaselkl
Catallaxy Services consulting:
https://CSmore.info/contact