This repository walks you through creating and deploying a data app in Python using Streamlit. It contains:
- A motivating example. What problem does Streamlit solve?
- A small demo app to get you started. This app contains interesting, real-world data.
- Instructions for installing, running, and modifying the demo app on your local machine.
- Exercises for improving the app. Solving these problems will help you learn Streamlit.
- Instructions for deploying your finished app to the internet. This will let you share it with friends and family.
You can view the final app you will build here.
This tutorial assumes that you have some familiarity with the terminal / command line. It also assumes that you have git installed on your local machine.
Prior experience with git and Python is helpful but not necessary.
You do not need to have Python installed prior to starting this tutorial.
I frequently use Jupyter Notebooks to convey analytical results. Each notebook typically imports a dataset, transforms it, and then presents a visualization or two. In short, each notebook tells a story about a dataset.
Streamlit lets me convert the code in my Notebooks to a web application. Instead of telling a story, I am now giving people a tool to explore the dataset themselves.
Click here to see an example.
- Fork this repository in Github (instructions).
- Clone your fork to your local machine (instructions).
- Install uv (instructions).
- In your terminal, navigate to the directory that contains this repo and type
uv sync. This will create a virtual environment in the project's.venvdirectory.
The above instructions need to be executed just once.
After completing the steps in the "Setup" section you can run the demo app.
- First activate the project's virtual environment: In the terminal, navigate to the project's directory and type
source .venv/bin/activate. - Then type
streamlit run streamlit_app.pyin the terminal.
A browser should open that contains the demo app. It should look like this:
- While the app is running, open the file streamlit_app.py. Can you guess what each line of the file does?
- Streamlit apps can reload after you make changes to the source code. That is, you don't need to stop and restart the app to see the result of your changes.
- While the app is running, change the text in the
st.headercall (line 7) to be "Changes in US State Demographics Over Time". Save the file. - The app should now have a button in the upper right that says "Rerun". Click it. The app should update with the new text.
The best way to learn Streamlit is to solve small, real-world problems on an existing app. Open the file exercises.md and try to complete the tasks listed there. They ask you to modify the demo app by:
- Adding a new graph.
- Adding a new input widget.
- Using the value from input widgets when creating a graph.
- Using tabs to make the app easier to navigate.
These are common tasks when working in Streamlit. If you get stuck, check my solutions in solution_app.py.
After you have finished the exercises, commit your changes and push them to Github.
Streamlit makes it easy to share your app with others. When your app is running, there should be a "Deploy" button in the upper right. Click it and follow the instructions that appear.
I encourage you to share your app with friends and family!
Congratulations: You have now cloned, modified, and deployed your first Streamlit app!
If you found this tutorial helpful, please give the repo a star and share it with your friends.
If you have feedback on the tutorial, feel free to reach out via my website: AriLamstein.com.