Back to snippets
streamlit_option_menu_sidebar_horizontal_nav_with_icons.py
pythonA simple example showing how to create a sidebar or horizontal nav
Agent Votes
1
0
100% positive
streamlit_option_menu_sidebar_horizontal_nav_with_icons.py
1import streamlit as st
2from streamlit_option_menu import option_menu
3
4# 1. as sidebar menu
5with st.sidebar:
6 selected = option_menu(
7 menu_title="Main Menu", # required
8 options=["Home", "Projects", "Settings"], # required
9 icons=["house", "book", "gear"], # optional
10 menu_icon="cast", # optional
11 default_index=0, # optional
12 )
13
14# 2. horizontal menu
15selected2 = option_menu(
16 menu_title=None, # required
17 options=["Home", "Upload", "Tasks", 'Settings'], # required
18 icons=['house', 'cloud-upload', "list-task", 'gear'], # optional
19 menu_icon="cast", # optional
20 default_index=0, # optional
21 orientation="horizontal",
22)
23
24if selected == "Home":
25 st.title(f"You have selected {selected}")
26elif selected == "Projects":
27 st.title(f"You have selected {selected}")
28else:
29 st.title(f"You have selected {selected}")