Data Visualization with Streamlit: An Interactive Dashboard in the Cloud


Data Visualization with Streamlit: An Interactive Dashboard in the Cloud
Today, data analysis is not just about interpreting numbers, but also about presenting them clearly, interactively, and in a visually appealing way. One tool that has gained popularity for its simplicity and power is Streamlit.
In this article, we will explore what Streamlit is, its advantages, and build a small interactive dashboard step-by-step, deploying it to the cloud.
What is Streamlit?
Streamlit is a Python library designed to create interactive web applications focused on data and machine learning.
Its main appeal is that it allows you to build fully functional interfaces without requiring frontend knowledge (HTML, CSS, or JavaScript).
Some key features:
It is completely open-source.
It allows you to build dynamic dashboards in minutes.
It integrates seamlessly with libraries like Pandas, Matplotlib, Plotly, among others.
It enables simple deployment to the Streamlit Cloud platform.
Advantages of Using Streamlit
Simplicity: With just a few lines of code, you can have a working web app.
Real-time updates: Any changes to your script are instantly reflected in the app.
Interactivity: Includes inputs like sliders, buttons, forms, and interactive charts.
Easy deployment: You can share your app via a public URL effortlessly.
Project Development: Sales Analysis Dashboard
Next, we’ll build a small dashboard to visualize sales data from a CSV file.
Step 1: Install Streamlit and matplotlib
First, we need to install Streamli and matplotlibt in our Python environment. Open a terminal and run:
pip install streamlit
pip install matplotlib
Step 2: Create the Main File
Create a new file named app.py with the following content:
pythonCopiarEditarimport streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
# Main title
st.title('Interactive Sales Dashboard')
# File uploader
csv_file = st.file_uploader("Upload your CSV file", type=["csv"])
# If a file is uploaded
if csv_file:
# Read the file
data = pd.read_csv(csv_file)
# Display the dataframe
st.subheader('Data Preview')
st.dataframe(data)
# Select a column to analyze
column = st.selectbox('Select a column to analyze:', data.columns)
# Create a distribution plot
st.subheader(f'Distribution of values in {column}')
fig, ax = plt.subplots()
data[column].hist(bins=20, ax=ax, color='skyblue', edgecolor='black')
plt.xlabel(column)
plt.ylabel('Frequency')
plt.grid(True)
st.pyplot(fig)
Step 3: Run the Project Locally
In the terminal, in the folder where you saved app.py, run:
streamlit run app.py
This will open your browser and show the dashboard locally at http://localhost:8501.
Step 4: Publish to the Cloud (Streamlit Cloud)
After confirming that it works locally, we can deploy it to the cloud:
1. Create a GitHub repository
Sign in to GitHub
Create a new repository
Upload your app.py file to that repository.
LINK: https://github.com/andresebast161616/Streamlit.git
2. Create a Streamlit Cloud account
Go to Streamlit Cloud.
Sign up (you can use your GitHub account).
Click on "New app".
Select the repository where you uploaded
app.py
.Click "Deploy".
That's it! In just a few seconds, you’ll have a public URL where your application is live, and anyone can interact with it
LINK: https://appgit-ffsfr8jaikfthcotgwptbk.streamlit.app/
Conclusión
Streamlit has democratized the creation of web applications for data analysis, reducing complexity to just a few Python commands. Thanks to its easy implementation and powerful capabilities to build interactive dashboards, it has become an essential tool for analysts, data scientists, and anyone who needs to share insights visually. Using Streamlit not only enhances the presentation of your results but also brings you closer to agile and accessible data-driven decision-making.
Subscribe to my newsletter
Read articles from Andree Sebastian FLORES MELENDEZ directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
