Fri. May 17th, 2024

Streamlit is an open-source library that allows you to create interactive web apps for data science and machine learning in Python. It has a simple, intuitive API that makes it easy to build and deploy web applications quickly. One of the features of Streamlit is the ability to create a side menu bar in your app, which can be used to provide navigation, filtering, or other interactive controls for your app.

To create a side menu bar in Streamlit, you can use the sidebar function. For example:

import streamlit as st

st.sidebar.title("Menu")
st.sidebar.selectbox("Choose an option", ["Option 1", "Option 2"])

This code creates a side menu bar with a title of “Menu”, and a dropdown menu with the options “Option 1” and “Option 2”. The sidebar function also allows you to add other types of controls, such as checkboxes, radio buttons, and text inputs.

Once you have added the controls you want to include in the side menu bar, you can use them in your app to filter or manipulate the data or other elements of your app. For example, you could use the selected option from the dropdown menu to filter a dataframe or plot:

import streamlit as stimport pandas as pd

df = pd.read_csv("data.csv")

selected_option = st.sidebar.selectbox("Choose an option", ["Option 1", "Option 2"])

if selected_option == "Option 1":
    df = df[df["column"] == "value"]
elif selected_option == "Option 2":
    df = df[df["column"] == "other value"]

st.plotly_chart(df)

In this code, the selected option from the side menu is used to filter the dataframe df, and the resulting data is used to create a plot using the plotly_chart function from Streamlit.

Overall, the side menu bar is a useful feature of Streamlit that allows you to add interactive controls to your app, and to use those controls to filter and manipulate your data. It is an important part of creating dynamic and engaging apps with Streamlit.


Youtube channel @techietechplace

Leave a Reply

Your email address will not be published. Required fields are marked *