create a streamlit application with a left menu with main options and suboptions; they have to be in color gray
Drop files here
or click to upload
import streamlit as st
# Custom CSS to style the sidebar menu
st.markdown("""
<style>
.css-1d391kg {
background-color: #f0f0f0;
}
.sidebar-menu {
color: gray;
cursor: pointer;
margin-bottom: 10px;
}
.sub-menu {
margin-left: 20px;
color: gray;
font-size: 0.9em;
}
</style>
""", unsafe_allow_html=True)
# Initialize session state for menu toggles if not exists
if 'menu_state' not in st.session_state:
st.session_state.menu_state = {
'dashboard': False,
'analytics': False,
'settings': False
}
# Sidebar
with st.sidebar:
st.title("Menu")
# Dashboard Menu
if st.button("📊 Dashboard", key="dashboard_btn",
help="Dashboard options",
use_container_width=True):
st.session_state.menu_state['dashboard'] = not st.session_state.menu_state['dashboard']
if st.session_state.menu_state['dashboard']:
with st.container():
st.markdown('<div class="sub-menu">📈 Overview</div>', unsafe_allow_html=True)
st.markdown('<div class="sub-menu">📉 Statistics</div>', unsafe_allow_html=True)
st.markdown('<div class="sub-menu">📊 Reports</div>', unsafe_allow_html=True)
# Analytics Menu
if st.button("📈 Analytics", key="analytics_btn",
help="Analytics options",
use_container_width=True):
st.session_state.menu_state['analytics'] = not st.session_state.menu_state['analytics']
if st.session_state.menu_state['analytics']:
with st.container():
st.markdown('<div class="sub-menu">🔍 Data Analysis</div>', unsafe_allow_html=True)
st.markdown('<div class="sub-menu">📊 Visualizations</div>', unsafe_allow_html=True)
st.markdown('<div class="sub-menu">📑 Reports</div>', unsafe_allow_html=True)
# Settings Menu
if st.button("⚙️ Settings", key="settings_btn",
help="Settings options",
use_container_width=True):
st.session_state.menu_state['settings'] = not st.session_state.menu_state['settings']
if st.session_state.menu_state['settings']:
with st.container():
st.markdown('<div class="sub-menu">👤 Profile</div>', unsafe_allow_html=True)
st.markdown('<div class="sub-menu">🔒 Security</div>', unsafe_allow_html=True)
st.markdown('<div class="sub-menu">⚙️ Preferences</div>', unsafe_allow_html=True)
# Main content area
st.title("Main Content")
st.write("Select an option from the sidebar menu to get started.")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?