05-visualization
5.0 Overview
In this section, we will run the Flask application that serves as the user interface for our weather data pipeline. The Flask app components have been pre-created, so we'll focus on building and running the containerized application using Docker Compose.
By the end of this section, you will have:
- Built and run the Flask application container using Docker Compose.
- Accessed the web-based user interface in your browser.
- Viewed visualizations of the weather data stored in the PostgreSQL database.
This section demonstrates how to bring together the data processing pipeline and the user interface, allowing you to interact with and visualize the processed weather data through a web application. It showcases the power of containerization in creating a complete, interconnected data analysis and visualization system.
Prerequisites
Before starting this lesson, please ensure that you have:
- Completed the 04-user-interface lesson
- Docker and Docker Compose installed on your system
- A web browser to access the Flask application
Lesson Content
5.1 Run the flask app
The components of the Flask app have already been created for you. All you need to do now is run the Docker Compose build and you will be able to see the flask app in action.
-
Open a new terminal window and navigate to the
flask-app
folder:cd ../flask-app
-
You will now build and run the containerized flask app by running the following command:
docker-compose up
This command does several things:
- Builds the Docker image for the Flask app if it hasn't been built yet
- Creates and starts a container for the Flask app
- Attaches to the container's output, showing you the logs in real-time
-
Once the Flask app is running, you can access it in your web browser at: http://127.0.0.1:5000.
You should see a web page with visualizations of the weather data. If you encounter any issues, check the terminal where you ran
docker-compose up
for error messages. -
The Flask app references data from the PostgreSQL database, which was set up when running the docker-compose up command in step 4 of the previous section.
This demonstrates how our containerized services work together: the Flask app container can communicate with the PostgreSQL container, retrieving and visualizing the data that was processed by our ETL pipeline.
5.2 Exploring the Visualizations
Once you've accessed the Flask app in your browser, take some time to explore the visualizations:
- Look at the overall structure of the page. How is the information organized?
- Examine each chart or graph. What kind of weather data is being displayed?
- Are there any interactive elements? Try clicking on different parts of the visualizations.
- Consider how this data presentation compares to looking at raw data in a database or spreadsheet.
5.3 Adding more visualizations
The current Flask app provides a starting point for data visualization. As a researcher, you might want to add more visualizations or modify existing ones to better suit your specific research questions. Here are some ideas for extending the app:
- Add a time series plot showing temperature trends over time.
- Create a map visualization showing weather patterns across different locations.
- Implement a feature allowing users to filter data by date range or location.
- Add statistical summaries of the weather data.
To add these features, you would need to modify the Flask app's Python code and HTML templates. This process would involve:
- Updating the queries in
app.py
to fetch the necessary data from the database. - Creating new routes in
app.py
to handle additional pages or data requests. - Modifying the HTML templates to include new charts or interactive elements.
- Possibly adding new JavaScript code for client-side interactivity.
Remember, after making changes to the Flask app, you'll need to rebuild and restart the Docker container to see the updates.
Conclusion
In this lesson, you've brought together all the components of your containerized weather data pipeline. You've run a Flask application that visualizes the data processed by your ETL pipeline, all within a containerized environment. This demonstrates how Docker can be used to create complex, multi-service applications for data analysis and visualization.
Key Points
- Docker Compose simplifies the process of running multi-container applications
- Web-based visualizations make data more accessible and understandable
- Containerization allows for consistent deployment of both data processing and visualization components
- Flask provides a powerful platform for creating custom data visualization applications