Dashboard Increíble con Python y Streamlit ⚡ ¡Crea Apps Pro sin HTML en solo 15 minutos!
Creating a Professional Dashboard with Python and Streamlit
Introduction to the Project
- The speaker introduces the concept of creating a professional-looking dashboard using Python, emphasizing that it can be done quickly and for free.
- Streamlit is introduced as a tool that transforms standard Python code into an intuitive web application without needing HTML knowledge.
Setting Up the Environment
- Instructions are provided to create a project folder named "dashboard" and open it in Visual Studio Code.
- The speaker discusses installing necessary libraries: Streamlit for the interface, pandas for data manipulation, and Plotly for graphics. A virtual environment is recommended but not mandatory.
Initializing the Application
- The initial setup involves importing libraries: Streamlit as
st, pandas aspd, and Plotly's express module.
- Configuration of the Streamlit page is demonstrated, including setting the title ("My Dashboard Pro") and layout options.
Creating Sample Data
- The speaker explains how to create sample data representing sales figures from January to June, which will be used in a DataFrame.
- A new title ("Dashboard Ejecutivo Pro") is added to differentiate between sections within the app.
Adding Content to the Dashboard
- Markdown formatting is introduced for adding text elements like titles; specifically, level three headings are used for "Real-Time Analysis."
- Four columns are created using
st.columns, allowing organized placement of metrics within each column.
Displaying Metrics
- Metrics are generated using
st.metricto display total sales alongside their calculated sum from the DataFrame.
Creating Interactive Metrics and Graphs in Data Analysis
Setting Up Metrics
- The discussion begins with the creation of a dynamic metric that allows for comparison with previous months, ensuring values are adjustable through formulas rather than static numbers.
- A second metric is introduced to track active clients, showing an increase of 23 clients, which updates intuitively on the dashboard.
- The third metric focuses on calculating monthly averages for sales, formatted as integers without decimals, while also incorporating an 8% growth rate.
- A fourth metric is established to represent Return on Investment (ROI), using a constant value of 245 and a growth percentage of 15%, contributing to the overall dashboard setup.
Creating Interactive Graphs
- An interactive line graph is created using Plotly Express, plotting sales data against months with appropriate titles and markers for clarity.
- The layout of the graph can be customized; users are encouraged to select templates that suit their preferences, such as 'plotlif dark' for better visibility.
- Users can modify graph types and layouts dynamically. Errors encountered during initial setups are addressed promptly to ensure smooth functionality.
Implementing Circular Graphs
- A circular chart is introduced due to its popularity among viewers; it visualizes client distribution by region effectively.
- This pie chart utilizes data from the dataframe and allows users to interactively explore client distributions across different regions.
Enhancing User Interaction
- Features like full-screen viewing and image downloading options enhance user experience when interacting with graphs.
- Users can zoom in/out on charts for detailed analysis; these functionalities contribute significantly to data exploration.
Adding Filters for Data Control
- A sidebar filter is implemented using Streamlit's sidebar feature, allowing users to control data views based on selected criteria such as month or region.
Filtering Data in Streamlit
Understanding Unique Filters for Regions
- The speaker discusses filtering data by region, specifically focusing on the "punic" region to extract unique regions from the dataset.
- It is noted that while months are unique and do not require a filter, regions may repeat (e.g., "norte" appears three times), necessitating the use of a unique filter.
Creating Filtered DataFrames
- A variable named
dato filtradois introduced to store filtered data based on whether a selected region exists within the filter criteria.
- The speaker demonstrates how selecting different regions affects the visibility of the DataFrame; it only displays when at least one region is selected.
Interactivity with Filters
- The importance of interactivity is highlighted; selecting or deselecting regions dynamically alters the displayed DataFrame content.
- Suggestions are made for implementing additional filters, such as month selection, emphasizing that these should be placed strategically in the code for effective functionality.
Dashboard Creation Insights
- The speaker expresses satisfaction with creating a professional-looking dashboard using Streamlit, indicating this is just an initial step in mastering the tool.
Community Engagement and Future Learning Opportunities