DEV Community

Cover image for Creating a Sales Analysis Application with Streamlit: A Practical Approach to Business Intelligence
TELL IVAN CASILLA MAQUERA
TELL IVAN CASILLA MAQUERA

Posted on

Creating a Sales Analysis Application with Streamlit: A Practical Approach to Business Intelligence

Introduction:
Streamlit is a powerful open-source tool that allows you to create interactive web applications for data analysis and visualization with just a little Python code. In this article, we'll explore how to use Streamlit to build a sales analysis application, providing a practical approach to business intelligence. We'll learn how to generate sample data, visualize key information, create interactive charts, and deploy our application to the cloud.

Setting up the Environment:
To get started, we'll need to install the following Python libraries:

Image description

-Streamlit is the main library that will allow us to
create the web application.
-Pandas will be used for data manipulation and
analysis.
-Plotly will help us create attractive and
interactive data visualizations.

Let's explore the code step by step:

Image description

In this section, we import the necessary libraries and generate a sample dataset using a Pandas DataFrame. This DataFrame contains information about different products, such as their name, category, sales, costs, and region.

Image description

Here, we configure the Streamlit application page by setting a title and a "wide" layout to better utilize the available space. Then, we display the sales data in our application using st.header and st.write.

Image description

In this section, we create an interactive bar chart that displays total sales by region. First, we group the data by region and sum the sales using Pandas. Then, we use the plotly.express library to create the chart and display it in our application with st.plotly_chart.

Image description

Similarly, we create an interactive pie chart that shows the distribution of sales by product category.

Image description

Finally, we display some key performance indicators (KPIs) important for a business, such as total sales, total cost, and net profit. We use st.columns to divide the screen into three columns and display a KPI in each one.

Running the Application:
To run the application locally, follow these steps:

1.-Save the above code in a file called ejemplo.py.

Image description

2.-Open a terminal or command prompt and navigate to the directory
where app.py is located.

Image description

3.-Run the following command: streamlit run app.py.

Image description

4.-The application will open in your local web browser, and you'll
be able to interact with the charts and explore the data from
different perspectives.

Image description

Image description

Image description

Image description

Deploying to Streamlit Cloud:
Streamlit Cloud is a service that allows us to deploy our Streamlit applications to the cloud effortlessly. To do so, follow these steps:

1.-Create a repository on GitHub and upload the app.py file.

Image description

2.-Go to https://streamlit.io, log in, and create a new app from your GitHub repository.

Image description

3.-Streamlit Cloud will deploy your application and provide you with a public URL to access it from anywhere.

https://app-b8tbb4n9vpnghxjbnktkpm.streamlit.app/

Image description

Image description

Image description

Next Steps:
This application is just a basic example, but you can improve and expand it in several ways, such as:

-Loading real data from different sources (databases,CSV files,
APIs, etc.).
-Adding more analyses and visualizations, such as line charts,scatter plots, heatmaps, etc.
-Implementing data filtering and sorting functions.
-Generating automatic reports in different formats (PDF, Excel, etc.).
-Integrating user authentication and access control.

The flexibility and potential of Streamlit are
enormous, allowing you to create more complex and
customized business intelligence applications based
on your specific needs.

Conclusion:
In this article, we've explored how Streamlit can simplify the creation of interactive web applications for data analysis and business intelligence. We've built an application that analyzes sales data, displays key information through interactive charts and KPIs, and learned how to deploy it to the cloud using Streamlit Cloud.

Streamlit is a powerful tool that combines ease of use with the ability to create complex applications. I encourage you to explore Streamlit and discover how it can help you transform your data into valuable information for decision-making in your business.

I hope this article has been helpful and inspires you to begin your own journey with Streamlit. Enjoy creating interactive and attractive business intelligence applications!

Top comments (0)