Introducing streamlit-scroll-navigation: flexible scroll-based navigation for Streamlit
Hey everyone, I’m excited to introduce streamlit-scroll-navigation, a customizable scroll-based navigation component for Streamlit apps.
I love the aesthetic of scrollable single-page applications (SPA). They elegantly present multiple sections of content without requiring users to navigate across different pages. With streamlit-scroll-navigation, you can easily create SPA pages in Streamlit. This component enables smooth scroll-based navigation for portfolios, data stories, or other apps that present multiple sections on the same page.
Demo:
Features
- Smooth Animations: Scrolling to anchors on the page feels fluid and seamless.
- Anchor tracking: As the user scrolls, the active anchor automatically updates to the nearest visible anchor.
- Configurable Icons: Customize Bootstrap icons for each navigation option and the menu title to give your app a personal touch.
- Configurable Styles: Edit CSS attributes with the
override_stylesparameter for additional customization. - Styled with Bootstrap: The component comes styled with Bootstrap for a sleek and responsive design.
Installation
To install, simply run:
pip install streamlit-scroll-navigation
Parameters
scroll_navbar() accepts the following parameters:
anchor_ids(required): The list of anchor IDs representing the sections or points to navigate.menu_title(optional, default='Menu'): The title of the scroll navigation menu.icons(optional, default=[]): A list of Bootstrap icon names corresponding to each navigation option.default_index(optional, default=0): The index of the initially selected item.orientation(optional, default='vertical'): The orientation of the navigation (either'vertical'or'horizontal').
The function returns the currently selected anchor’s ID.
Example
This examples contains 2 scroll navigation bars with different orientations. Explore example.py for more use cases.
# Create a dummy streamlit page
import streamlit as st
from streamlit_scroll_navigation import scroll_navbar
# Anchor IDs and icons
anchor_ids = ["About", "Features", "Settings", "Pricing", "Contact"]
anchor_icons = ["info-circle", "lightbulb", "gear", "tag", "envelope"]
# 1. as sidebar menu
with st.sidebar:
st.subheader("Example 1")
scroll_navbar(
anchor_ids,
anchor_labels=None, # Use anchor_ids as labels
anchor_icons=anchor_icons)
# 2. horizontal menu
st.subheader("Example 2")
scroll_navbar(
anchor_ids,
key = "navbar2",
anchor_icons=anchor_icons,
orientation="horizontal")
# Dummy page setup
for anchor_id in anchor_ids:
st.subheader(anchor_id,anchor=anchor_id)
st.write("content " * 100)
Give it a try and let me know your feedback, questions, or if you want to contribute!