Air Quality Analysis with Preswald

Amrutha GujjarAmrutha Gujjarβ€’β€’3 min read

Category: Community


We're thrilled to feature Aneesh Maturu in this edition of the Preswald Community Showcase! πŸŽ‰ Aneesh has built an impressive Preswald app that analyzes and visualizes air quality data using interactive charts and tables.

Project Overview

πŸ“Š Preswald and Analytics

This blog explores how Preswald utilizes analytics to monitor air quality trends, providing insights into pollution levels, AQI variations, and environmental impact through dynamic visualizations.

Project Name: Air Quality Explorer<br>Built by: <a target="_blank" rel="noopener noreferrer nofollow" class="text-blue-600 hover:text-blue-800 underline" href="https://github.com/aneeshmaturu2002">Aneesh Maturu</a><br>Dataset: Air quality dataset

<a target="_blank" rel="noopener noreferrer nofollow" class="text-blue-600 hover:text-blue-800 underline" href="https://github.com/aneeshmaturu2002/preswald/blob/main/examples/airquality/hello.py">Check out the project on GitHub</a>

πŸ“Š Description

Aneesh's project provides an interactive dashboard for exploring air quality data. The app allows users to:

<li>**Filter air quality data** by location, pollutant type, and time frame. </li><li>**Visualize trends** using **Plotly charts** to analyze pollution patterns and AQI fluctuations. </li><li>**Compare air quality across cities** dynamically in an interactive table. </li><li>**Gain insights** into pollution sources and environmental health indicators. </li>With Preswald, Aneesh has created a **seamless user experience**, where users can dynamically adjust inputs and get instant updates without writing frontend code. <hr>## πŸš€ Code Snippets

Here’s a sneak peek at how Aneesh's project is structured:

Loading the Data

from preswald import connect, get_df, text

connect()  # Establish connection to data

# Load air quality dataset
airquality_df = get_df("air_quality")

Creating an Interactive AQI Trend Chart

from preswald import plotly
import plotly.express as px

fig = px.line(airquality_df, x='date', y='AQI', color='location',
             title='Air Quality Index (AQI) Trends')
plotly(fig)

Displaying Air Quality Data in a Table

from preswald import table

table(airquality_df[['date', 'location', 'AQI', 'pollutant']])

With just a few lines of Python, Aneesh has built a fully interactive data app powered by Preswald! πŸš€

What is Preswald?

Preswald is an open-source framework for building data apps, dashboards, and internal tools with just Python. It provides pre-built UI components like tables, charts, and forms, so you don't have to write frontend code. Users can interact with your app, changing inputs, running queries, and updating visualizations, without you needing to manage the UI manually.

Preswald tracks state and dependencies, making computations efficient by updating only when necessary. It uses a workflow DAG to manage execution order, ensuring performance and predictability. Preswald allows you to turn Python scripts into shareable, production-ready applications easily.

Key Features

<li>Add UI components to Python scripts: user-interactive buttons, text inputs, tables, and charts. </li><li>Stateful execution with automatic state tracking and updates. </li><li>Structured computation using a DAG-based execution model. </li><li>Deploy with a single command. </li><li>Query and display live data from various sources. </li><li>Build interactive reports and dashboards. </li><li>Easy local or cloud hosting. </li><li>Shareable via a simple link. </li>## **πŸš€ Getting Started**

Installation

First, install Preswald via pip: <a target="_blank" rel="noopener noreferrer nofollow" class="text-blue-600 hover:text-blue-800 underline" href="https://pypi.org/project/preswald/">https://pypi.org/project/preswald/</a>

pip install preswald

πŸ‘©β€πŸ’» Quick Start

1. Initialize a New Project

To start using Preswald, initialize a new project:

preswald init my_project
cd my_project

This creates a folder <code class="rounded-md bg-gray-100 px-1.5 py-0.5 font-mono text-sm">my_project</code> with essential files:

<li><code class="rounded-md bg-gray-100 px-1.5 py-0.5 font-mono text-sm">hello.py</code>: Your first Preswald app. </li><li><code class="rounded-md bg-gray-100 px-1.5 py-0.5 font-mono text-sm">preswald.toml</code>: Settings for your app. </li><li><code class="rounded-md bg-gray-100 px-1.5 py-0.5 font-mono text-sm">secrets.toml</code>: Secure sensitive information. </li><li><code class="rounded-md bg-gray-100 px-1.5 py-0.5 font-mono text-sm">.gitignore</code>: Keep <code class="rounded-md bg-gray-100 px-1.5 py-0.5 font-mono text-sm">secrets.toml</code> safe from version control. </li>**2. Write Your First App**

Open <code class="rounded-md bg-gray-100 px-1.5 py-0.5 font-mono text-sm">hello.py</code> and write:

from preswald import text, plotly, connect, get_df, table
import pandas as pd
import plotly.express as px

text("# Welcome to Preswald!")
text("This is your first app. πŸŽ‰")

# Load CSV data
connect() # loads default sample CSV
df = get_df('sample_csv')

# Create a scatter plot
fig = px.scatter(df, x='quantity', y='value', text='item',
                 title='Quantity vs. Value')
fig.update_traces(textposition='top center')
fig.update_layout(template='plotly_white')

# Show plot and data
table(df)

3. Run Your App

Launch the app with:

preswald run

4. Deploy Your App to the Cloud

Deploy your app using:

preswald deploy --target structured

Your app will be built and accessible online.

<hr>## Huge Thanks to Aneesh Maturu!

A big thank you to Aneesh Maturu for sharing their work and inspiring the Preswald community! Want to see more of their work? Check them out on <a target="_blank" rel="noopener noreferrer nofollow" class="text-blue-600 hover:text-blue-800 underline" href="https://github.com/aneeshmaturu2002">GitHub</a>.

Want to Contribute?

Got a cool idea for a Preswald app? We'd love to see it! Get started here: <a target="_blank" rel="noopener noreferrer nofollow" class="text-blue-600 hover:text-blue-800 underline" href="https://github.com/StructuredLabs/preswald">https://github.com/StructuredLabs/preswald</a> and get featured in our next Community Showcase.

Happy building! πŸš€