create an application with login and login page should have logo and title. Once logedin, show logo and title in side bar with three menu button in the side bar. if side bar button click show filter and above filter show one pie chart and dataframe and below complete data
To upload files, please first save the app
import streamlit as st
from PIL import Image
import pandas as pd
import numpy as np
# Initialize session state
if 'logged_in' not in st.session_state:
st.session_state.logged_in = False
# Page config
st.set_page_config(page_title="Dashboard", layout="wide")
# Load and display logo
logo = Image.new('RGB', (200, 100), 'blue') # Placeholder logo
def login():
st.image(logo, width=200)
st.title("Welcome to Dashboard")
username = st.text_input("Username")
password = st.text_input("Password", type="password")
if st.button("Login"):
if username == "admin" and password == "admin": # Simple validation
st.session_state.logged_in = True
st.rerun()
else:
st.error("Invalid credentials")
def main():
# Sidebar
with st.sidebar:
st.image(logo, width=150)
st.title("Dashboard")
# Menu buttons
selected = st.radio("Menu", ["Sales", "Inventory", "Analytics"])
# Main content
if selected == "Sales":
show_sales_dashboard()
elif selected == "Inventory":
show_inventory_dashboard()
else:
show_analytics_dashboard()
def generate_sample_data():
np.random.seed(42)
dates = pd.date_range(start='2023-01-01', end='2023-12-31', freq='D')
data = {
'Date': dates,
'Category': np.random.choice(['Electronics', 'Clothing', 'Food', 'Books'], size=len(dates)),
'Sales': np.random.randint(100, 1000, size=len(dates)),
'Quantity': np.random.randint(10, 100, size=len(dates))
}
return pd.DataFrame(data)
def show_sales_dashboard():
st.title("Sales Dashboard")
# Filters
col1, col2 = st.columns(2)
with col1:
category = st.multiselect("Category", ["Electronics", "Clothing", "Food", "Books"])
with col2:
date_range = st.date_input("Date Range", value=(pd.to_datetime('2023-01-01'), pd.to_datetime('2023-12-31')))
# Load data
df = generate_sample_data()
# Apply filters
if category:
df = df[df['Category'].isin(category)]
df = df[(df['Date'] >= pd.to_datetime(date_range[0])) & (df['Date'] <= pd.to_datetime(date_range[1]))]
# Pie chart
pie_data = df.groupby('Category')['Sales'].sum()
st.subheader("Sales by Category")
st.pie_chart(pie_data)
# Summary DataFrame
st.subheader("Summary")
summary = df.groupby('Category').agg({
'Sales': ['sum', 'mean'],
'Quantity': ['sum', 'mean']
}).round(2)
st.dataframe(summary)
# Complete data
st.subheader("Detailed Data")
st.dataframe(df)
def show_inventory_dashboard():
st.title("Inventory Dashboard")
st.info("Inventory dashboard content will be displayed here")
def show_analytics_dashboard():
st.title("Analytics Dashboard")
st.info("Analytics dashboard content will be displayed here")
# Main app logic
if not st.session_state.logged_in:
login()
else:
main()
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?