An interactive web application for exploring FDA food contaminant data.
This application provides a user-friendly interface to explore and visualize FDA contaminant levels in various food commodities. Users can filter the data, search for specific information, and view visualizations to better understand the relationships within the data.
- Interactive Filtering: Filter data by contaminant, commodity, and level type
- Search Functionality: Search across all data fields
- Data Visualization: View contaminant distribution in a bar chart
- Responsive Design: Works on desktop and mobile devices
We offer two versions of this application:
- A traditional web application using HTML/CSS/JavaScript
- A Gradio-based Python application with enhanced filtering and visualization
- Python 3.7+ installed (required for the Gradio version)
- A modern web browser (Chrome, Firefox, Safari, or Edge)
-
Clone this repository:
git clone https://github.com/homer6/food-contaminants.git cd food-contaminants -
Create and activate a Python virtual environment:
# Create a virtual environment (use python3 on macOS/Linux if python command is not found) python -m venv venv # or python3 -m venv venv # Activate the virtual environment # On macOS/Linux: source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install required dependencies:
pip install -r requirements.txt
The Gradio application provides an enhanced user interface with better filtering options and interactive visualizations.
# Make sure your virtual environment is activated
python gradio_app.py
# or
python3 gradio_app.pyOpen your browser and navigate to http://127.0.0.1:7860
If you encounter any issues with visualizations not appearing in the full application:
# Run the simplified version to test basic visualization functionality
python3 simple_gradio_app.pyThe simple version provides a minimal interface with just a bar chart of the top 10 contaminants, which can help diagnose whether the issue is with the visualization library or with the filter logic in the full application.
IMPORTANT: The traditional web application cannot be run by directly opening the HTML file in a browser due to CORS security restrictions. You must use a local web server.
Start a Python HTTP server (this will run until you stop it with Ctrl+C):
# Make sure your virtual environment is activated
# Start server on default port 8000
python -m http.server
# or
python3 -m http.serverOpen your browser and navigate to http://localhost:8000
The Gradio application offers the following features:
-
Advanced Filtering
- Multi-select dropdowns: Select multiple contaminants, commodities, or level types at once
- Dropdown filters showing item counts for each option (e.g., "Lead (42)")
- Full-text search across all data fields
- Numeric filtering by minimum and maximum contaminant levels
- One-click filter reset button
-
Multiple Visualization Types
- Contaminant Distribution: Bar chart of most frequent contaminants
- Commodity Distribution: Bar chart of most frequent food commodities
- Level Type Distribution: Pie chart showing level type breakdown
- Heatmap: Visualize relationships between contaminants and commodities
- Level Type by Contaminant: Stacked bars showing level types for top contaminants
-
Data Analysis Features
- Summary statistics dashboard for filtered data
- Clean, paginated data table
- Record count indicators and warnings for large result sets
-
Interactive Experience
- Real-time updates when changing filters or visualization types
- Responsive design that works on various screen sizes
- Professional styling with modern typography and layout
When you're done, return to the terminal and press Ctrl+C to stop the server.
Note: If you see an error like
Failed to load resource: net::ERR_FAILEDorAccess to fetch has been blocked by CORS policy, it means you're trying to open the HTML file directly without using a web server.
Downloaded from FDA Chemical Contaminants Transparency Tool; http://hfpappexternal.fda.gov/scripts/fdcc/?set=contaminant-levels
- Last updated: 3/20/2025
- Downloaded: 3/22/2025
"Users of this table are encouraged to refer to the document listed in the reference column for additional explanation on how each contaminant level is applied."
Original source: https://www.hfpappexternal.fda.gov/scripts/fdcc/index.cfm?set=contaminant-levels
See the LICENSE file for details.