Replicate the app from the image.
To upload files, please first save the app
import streamlit as st
import pandas as pd
import numpy as np
# Set page config to wide mode
st.set_page_config(layout="wide")
# Create sample data
def generate_sample_data():
np.random.seed(42)
dates = pd.date_range(start='2023-01-01', end='2023-12-31', freq='D')
categories = ['Category A', 'Category B', 'Category C']
data = []
for date in dates:
for category in categories:
value = np.random.randint(100, 1000)
data.append({
'date': date,
'category': category,
'value': value
})
return pd.DataFrame(data)
# Create the main dataframe
df = generate_sample_data()
# Create two columns for the layout
col1, col2 = st.columns([1, 2])
# Filters column
with col1:
st.markdown("### Filters")
# Date range filter
date_range = st.date_input(
"Select Date Range",
value=(df['date'].min(), df['date'].max()),
min_value=df['date'].min(),
max_value=df['date'].max()
)
# Category filter
categories = st.multiselect(
"Select Categories",
options=df['category'].unique(),
default=df['category'].unique()
)
# Filter the data based on selections
filtered_df = df[
(df['date'] >= pd.Timestamp(date_range[0])) &
(df['date'] <= pd.Timestamp(date_range[1])) &
(df['category'].isin(categories))
]
# Chart column
with col2:
st.markdown("### Chart")
# Aggregate data by category
chart_data = filtered_df.groupby('category')['value'].sum().reset_index()
# Create bar chart
st.bar_chart(
data=chart_data,
x='category',
y='value',
use_container_width=True
)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?