📊

Inserting Navigation Menu into a Streamlit App

Jul 12, 2024

Inserting Navigation Menu into a Streamlit App

Introduction

  • Purpose: Demonstrate how to insert a navigation menu in a Streamlit app.
  • Examples: Navigation menu in sidebar and on the main page.
  • Preparation: Simple Streamlit app displaying a title.

Installing Required Library

  • Command: pip install streamlit-option-menu
  • Documentation link will be provided in the description.

Importing the Library

  • Code: from streamlit_option_menu import option_menu

Example 1: Navigation Menu in Sidebar

  • Easy to use module with straightforward implementation.
  • **Main Arguments: **
    • Menu title
    • Options to display
  • Storage: Selected option stored in variable selected.
  • Testing: Use if condition to display a title with the name of the selected option.
  • Display: Menu functions correctly; title changes based on user selection.
  • Optional: Set menu title to None to hide it.

Optional Arguments

  • Icons: Specify icons for each option from the Bootstrap website.
    • Example icons: house, book, envelope
    • Link to Bootstrap icons will be provided in description.
  • Menu Title Icon: Can also use an icon.
  • Default Index: Set which option should be selected first.
    • Index starts at 0 by default.

Example 2: Horizontal Navigation Bar on Main Page

  • Copy and adjust the previous sidebar example.
  • Orientation: Set argument to horizontal.
  • Menu Title: Set to None for a cleaner look.

Customization

  • Use the styles argument for further customization.
  • Customizable Elements: Background color, font size, etc.
  • Example code from documentation will be provided.

Conclusion

  • Summary: Covered both sidebar and main-page navigation menus with customization options.
  • Q&A: Comment section for questions.
  • Thanks & Outro: Thank the audience and sign off.