I have data on FDA Recalls. The App would review the data and present Trends in a chart.
To upload files, please first save the app
import streamlit as st
import pandas as pd
import altair as alt
st.title("FDA Recalls Analysis Dashboard")
# Load data
@st.cache_data
def load_data():
# NOTE: Using corsproxy.io because we're in a WASM environment. If running locally,
# you can remove the corsproxy.io prefix.
url = "https://corsproxy.io/?https://raw.githubusercontent.com/FDA/open.fda.gov/master/examples/recalls/recalls_sample.json"
df = pd.read_json(url)
df['recall_initiation_date'] = pd.to_datetime(df['recall_initiation_date'])
return df
try:
df = load_data()
# Show data overview
st.subheader("Data Overview")
st.write(f"Total number of recalls: {len(df)}")
# Time series analysis
st.subheader("Recalls Over Time")
recalls_by_date = df.groupby('recall_initiation_date').size().reset_index(name='count')
chart = alt.Chart(recalls_by_date).mark_line().encode(
x='recall_initiation_date:T',
y='count:Q',
tooltip=['recall_initiation_date', 'count']
).properties(
width=700,
height=400
)
st.altair_chart(chart, use_container_width=True)
# Classification Analysis
st.subheader("Recalls by Classification")
classification_counts = df['classification'].value_counts()
class_chart = alt.Chart(classification_counts.reset_index()).mark_bar().encode(
x='index:N',
y='classification:Q',
color='index:N',
tooltip=['index', 'classification']
).properties(
width=500,
height=300
)
st.altair_chart(class_chart, use_container_width=True)
# State Analysis
st.subheader("Recalls by State")
state_counts = df['state'].value_counts().head(10)
state_chart = alt.Chart(state_counts.reset_index()).mark_bar().encode(
x='index:N',
y='state:Q',
color='index:N',
tooltip=['index', 'state']
).properties(
width=500,
height=300
)
st.altair_chart(state_chart, use_container_width=True)
# Show raw data
st.subheader("Raw Data")
if st.checkbox("Show raw data"):
st.write(df)
except Exception as e:
st.error("Error loading or processing data. Please check if the data source is available.")
st.error(f"Error details: {str(e)}")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?