Registry / web-framework / streamlit-option-menu

streamlit-option-menu

JSON →
library0.4.0pypypi✓ verified 85d ago

streamlit-option-menu is a simple Streamlit component that allows users to select a single item from a list of options in a menu. It provides a static list of options with configurable icons and extensive CSS styling capabilities, offering an alternative to `st.selectbox()` for navigation. The current stable version is 0.4.0, with regular updates and community engagement.

pip install streamlit-option-menu
INSTALL
IMPORT
SIG · STREAMLIT-OPTION-M
S
streamlit-option-menu
web-frameworkpythonv0.4.0
Install
15.6s avg
Import
1334ms
Disk
435MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 1.721s · 447.4MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 15.6s · import 0.946s · 416MB
435MB installed
● package 435MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

option_menu
from streamlit_option_menu import option_menu

This example demonstrates how to create a vertical navigation menu in the sidebar using `streamlit-option-menu`, displaying different content based on the user's selection.

import streamlit as st from streamlit_option_menu import option_menu st.set_page_config(layout="wide") with st.sidebar: selected = option_menu( menu_title="Main Menu", # required options=["Home", "Projects", "Contact"], # required icons=["house", "code-slash", "envelope"], # optional menu_icon="cast", # optional default_index=0, # optional orientation="vertical" ) if selected == "Home": st.title(f"You selected: {selected}") st.write("Welcome to the Home page!") elif selected == "Projects": st.title(f"You selected: {selected}") st.write("Here are my projects.") elif selected == "Contact": st.title(f"You selected: {selected}") st.write("Contact me here.")
Debug
Known issues
gotchaThe `option_menu` UI may incorrectly refresh to its default state after `st.experimental_set_query_params` is called, even if the underlying selected value remains correct. The UI might not visually reflect the intended selection.
fix
Store and retrieve the selected value using `st.session_state` and explicitly pass it as `default_index` if the menu is re-rendered conditionally or after query parameter changes. This ensures the UI state aligns with the session state. Avoid relying solely on query parameters for menu state if UI desynchronization is observed.
affects: All versions where `st.experimental_set_query_params` is used with `option_menu`.
gotchaWhen deploying Streamlit applications to platforms like Streamlit Cloud, having both `Pipfile` (and `Pipfile.lock`) and `requirements.txt` in your repository can lead to dependency resolution errors where `streamlit-option-menu` is not found. Streamlit prioritizes which dependency file to use.
fix
Ensure you use only one dependency management file (`requirements.txt` is generally recommended for simplicity with Streamlit Cloud) and remove the other. If using `Pipfile`, ensure `streamlit-option_menu` is correctly listed and a `Pipfile.lock` is generated.
affects: All versions
gotchaLike most Streamlit components, `streamlit-option-menu` triggers a full app rerun when its value changes. If the component is displayed conditionally or hidden, its value might reset on subsequent reruns if not properly managed.
fix
Always store the selected value in `st.session_state` if the menu's visibility or parameters might change, and use `st.session_state` to set the `default_index` on subsequent renders to maintain the selection state.
affects: All versions
gotchaCustom CSS applied via the `styles` parameter might not always behave as expected or interact with the main Streamlit app's CSS. This is because custom components are often rendered within an iframe, isolating their styling from the parent document.
fix
Test custom CSS thoroughly within the component's `styles` dictionary. Be aware of the iframe isolation and that external CSS or global Streamlit theming might not directly affect the component's internal elements. For deeper customization, understanding Bootstrap CSS (which the component uses) can be beneficial.
affects: All versions
gotchaThe `manual_select` parameter is designed for one-time programmatic selection and behaves like a button. If `manual_select` is constantly set to an index, it can lead to unexpected behavior or prevent user interaction, as the menu will continuously try to re-select that option.
fix
Set `manual_select` only when a manual selection is intended, typically within a conditional block or based on an event. Ensure it is not set persistently on every rerun to allow normal user interaction.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'streamlit_option_menu'
The `streamlit-option-menu` library is not installed in your Python environment or the import statement is incorrect.
fix
First, ensure the library is installed: `pip install streamlit-option-menu`. Then, import it using `from streamlit_option_menu import option_menu`.
IndexError: list index out of range
The `default_index` provided to the `option_menu` function is outside the valid range of indices for the `options` list.
fix
Ensure `default_index` is an integer value between `0` and `len(options) - 1`, inclusive. For example, `default_index=0` for the first item.
streamlit.errors.StreamlitAPIException: The 'key' argument must be unique for each widget
Multiple instances of `option_menu` (or other Streamlit widgets) are being used in the app without providing a unique string value for their `key` argument.
fix
Assign a unique string to the `key` parameter for each `option_menu` component, e.g., `option_menu(..., key="unique_menu_1")`, `option_menu(..., key="unique_menu_2")`.
TypeError: option_menu() got an unexpected keyword argument 'some_invalid_arg'
An invalid or misspelled keyword argument was passed to the `option_menu` function, or the argument is not supported in the installed version.
fix
Refer to the `streamlit-option-menu` documentation to confirm the correct function signature and available keyword arguments (e.g., ensure you use `orientation` instead of `direction`).
Upgrade
Version history
0.4.0latest on PyPI · released Oct 9, 2024
Audit
Dependencies
streamlitrequiredCore dependency for any Streamlit custom component.
Agent activity
14 hits · last 30 days
node
10
OpenAI (training)
1
Resources
streamlit-option-menu — pip install streamlit-option-menu · libregistry