In Streamlit, you can enhance the organization of your application using a sidebar or a container. These tools help structure content effectively, improving user experience by making navigation and information presentation clearer.

Sidebar

The sidebar is a fixed area on the left side of the application. It is ideal for displaying elements such as filters, settings, or navigation controls, without interfering with the main content.

Practical Example of Sidebar Usage:

import streamlit as st

# Sidebar title and description
st.sidebar.title("Application Settings")
st.sidebar.write("Use the options below to configure the app.")

# Sidebar elements
user_name = st.sidebar.text_input("Enter your name:")
option = st.sidebar.selectbox("Choose a category:", ["Technology", "Health", "Finance"])
notify = st.sidebar.checkbox("Enable notifications")

# Displaying selected options in the main content
st.header(f"Welcome, {user_name if user_name else 'User'}!")
st.write(f"You selected: {option}")
st.write("Notifications are enabled." if notify else "Notifications are disabled.")

Note: Functions like st.spinner() and st.echo() do not work within the sidebar.

Container

A container is an invisible grouping element that helps structure content in a logical way. It is useful for organizing different sections of a page.

Example of Using a Container to Structure Content:

import streamlit as st

# Grouping elements within a container
with st.container():
    st.subheader("User Profile")
    col1, col2 = st.columns(2)
    with col1:
        st.text_input("First Name")
    with col2:
        st.text_input("Last Name")
    st.text_area("Bio", "Tell us about yourself...")

# Content outside the container
st.subheader("Latest News")
st.write("Here you will find the latest updates and articles.")

Organizing Multiple Sections Using Containers:

with st.container():
    st.subheader("Featured Articles")
    st.write("Explore trending topics and insights.")
    st.button("Read More")

with st.container():
    st.subheader("User Feedback")
    st.text_area("Leave your feedback:")
    st.button("Submit")

By using sidebars and containers effectively, you can create well-structured, user-friendly applications. Experiment with these tools to improve organization and enhance the overall user experience!