create dashboard using bslib, contains Dashboard title, a control panel : a file input option, 5 select boxes, and on off button Main panel with reactive chart. use a simple theme, make the select buttons slim and sleek and good looking
To upload files, please first save the app
import streamlit as st
import pandas as pd
from pathlib import Path
import plotly.express as px
# Set page config
st.set_page_config(layout="wide")
# Custom CSS for slimmer select boxes
st.markdown("""
<style>
div[data-baseweb="select"] > div {
padding-top: 4px !important;
padding-bottom: 4px !important;
}
</style>
""", unsafe_allow_html=True)
# Create a sleek dashboard layout using bslib cards
with st.container():
st.title("đ Interactive Analytics Dashboard")
# Create two columns - control panel and main chart
col1, col2 = st.columns([1, 3])
with col1:
# Control Panel Card
with st.expander("Control Panel", expanded=True):
# File uploader
uploaded_file = st.file_uploader(
"Upload your CSV file",
type=['csv'],
help="Upload a CSV file to analyze"
)
# Select boxes with slim design
select1 = st.selectbox('Category', ['Option 1', 'Option 2', 'Option 3'], key='s1')
select2 = st.selectbox('Region', ['North', 'South', 'East', 'West'], key='s2')
select3 = st.selectbox('Time Period', ['Daily', 'Weekly', 'Monthly', 'Yearly'], key='s3')
select4 = st.selectbox('Metric', ['Sales', 'Revenue', 'Profit', 'Units'], key='s4')
select5 = st.selectbox('Comparison', ['Year over Year', 'Month over Month', 'None'], key='s5')
# Toggle switch
analysis_mode = st.toggle('Advanced Analysis Mode', value=False)
with col2:
# Main Chart Area
st.markdown("### Data Visualization")
if uploaded_file is None:
# Generate sample data when no file is uploaded
df = pd.DataFrame({
'Date': pd.date_range(start='2023-01-01', periods=100),
'Value': np.random.randn(100).cumsum()
})
# Create a sample chart
fig = px.line(df, x='Date', y='Value',
title='Sample Data Visualization')
fig.update_layout(
template='simple_white',
height=600,
margin=dict(l=20, r=20, t=40, b=20)
)
st.plotly_chart(fig, use_container_width=True)
st.info('đ Upload a CSV file to begin your analysis', icon="âšī¸")
else:
try:
df = pd.read_csv(uploaded_file)
# Create an actual chart based on uploaded data
# This is a placeholder visualization
fig = px.line(df)
fig.update_layout(
template='simple_white',
height=600,
margin=dict(l=20, r=20, t=40, b=20)
)
st.plotly_chart(fig, use_container_width=True)
except Exception as e:
st.error(f"Error reading the file: {str(e)}")
# Footer
st.markdown("---")
st.markdown("Created with Streamlit and â¤ī¸")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?