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
import pandas as pd
import plotly.express as px
from PIL import Image
import base64
from pathlib import Path
# Initialize session state variables
if 'authenticated' not in st.session_state:
st.session_state.authenticated = False
if 'username' not in st.session_state:
st.session_state.username = ''
# Function to generate sample data
def generate_sample_data():
data = {
'Category': ['A', 'B', 'C', 'D', 'E'] * 20,
'Value': [10, 20, 30, 40, 50] * 20,
'Region': ['North', 'South', 'East', 'West', 'Central'] * 20,
'Sales': [100, 200, 300, 400, 500] * 20
}
return pd.DataFrame(data)
# Create a simple logo
def create_logo():
# Create a simple colored rectangle as logo
img = Image.new('RGB', (200, 100), color='blue')
return img
# Save the logo
logo = create_logo()
logo.save('logo.png')
# Login page
def login_page():
col1, col2, col3 = st.columns([1,2,1])
with col2:
st.image('logo.png', width=200)
st.title('Company Dashboard')
username = st.text_input('Username')
password = st.text_input('Password', type='password')
if st.button('Login'):
# Simple authentication (in real app, use proper authentication)
if username == 'admin' and password == 'admin':
st.session_state.authenticated = True
st.session_state.username = username
st.rerun()
else:
st.error('Invalid credentials')
# Main dashboard
def main_dashboard():
# Sidebar
with st.sidebar:
st.image('logo.png', width=150)
st.title('Dashboard')
# Menu buttons
selected = st.radio('Menu', ['Sales Analysis', 'Performance Metrics', 'Reports'])
# Main content
if selected == 'Sales Analysis':
show_sales_analysis()
elif selected == 'Performance Metrics':
show_performance_metrics()
else:
show_reports()
def show_sales_analysis():
st.title('Sales Analysis')
# Filters
col1, col2 = st.columns(2)
with col1:
category_filter = st.multiselect('Category', ['A', 'B', 'C', 'D', 'E'])
with col2:
region_filter = st.multiselect('Region', ['North', 'South', 'East', 'West', 'Central'])
# Get data
df = generate_sample_data()
# Apply filters
if category_filter:
df = df[df['Category'].isin(category_filter)]
if region_filter:
df = df[df['Region'].isin(region_filter)]
# Create pie chart
fig = px.pie(df, values='Value', names='Category', title='Sales by Category')
st.plotly_chart(fig)
# Show summary dataframe
st.subheader('Summary Data')
summary_df = df.groupby(['Category', 'Region'])['Value'].sum().reset_index()
st.dataframe(summary_df)
# Show complete data
st.subheader('Complete Data')
st.dataframe(df)
def show_performance_metrics():
st.title('Performance Metrics')
# Filters
region_filter = st.multiselect('Region', ['North', 'South', 'East', 'West', 'Central'])
# Get data
df = generate_sample_data()
# Apply filters
if region_filter:
df = df[df['Region'].isin(region_filter)]
# Create pie chart
fig = px.pie(df, values='Sales', names='Region', title='Sales by Region')
st.plotly_chart(fig)
# Show summary and complete data
st.subheader('Summary Data')
summary_df = df.groupby('Region')['Sales'].sum().reset_index()
st.dataframe(summary_df)
st.subheader('Complete Data')
st.dataframe(df)
def show_reports():
st.title('Reports')
# Filters
time_period = st.selectbox('Time Period', ['Daily', 'Weekly', 'Monthly', 'Yearly'])
# Get data
df = generate_sample_data()
# Create pie chart
fig = px.pie(df, values='Value', names='Category', title='Category Distribution')
st.plotly_chart(fig)
# Show summary and complete data
st.subheader('Summary Data')
summary_df = df.groupby('Category')['Value'].mean().reset_index()
st.dataframe(summary_df)
st.subheader('Complete Data')
st.dataframe(df)
# Main app logic
def main():
if not st.session_state.authenticated:
login_page()
else:
main_dashboard()
if __name__ == '__main__':
main()
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?