Building a Multi-Page App with Streamlit ??
Streamlit is a popular Python library for creating interactive web applications with minimal effort. In this article, I'll explore how to build a multi-page app using Streamlit, allowing users to navigate through different sections seamlessly.
Setting Up the App
To get started, make sure you have Streamlit installed. You can install it using
pip install streamlit
Now, let's create a simple app with three pages: "Main Page," "Projects," and "Contact."
# Import Streamlit
import streamlit as st
# Set page configuration
st.set_page_config(
page_title="Multipage App",
page_icon="??",
)
# Main Page
st.title("Main Page")
st.sidebar.success("Select a page above.")
if "my_input" not in st.session_state:
st.session_state["my_input"] = ""
my_input = st.text_input("Input a text here", st.session_state["my_input"])
submit = st.button("Submit")
if submit:
st.session_state["my_input"] = my_input
st.write("You have entered:", my_input)
# Projects Page
st.title("Projects")
st.write("You have entered:", st.session_state["my_input"])
# Contact Page
st.title("Contact")
In the above code, we set up the Streamlit app with a title and configured page settings. The main page allows users to input text and submit it, while the "Projects" and "Contact" pages display the entered text.
Running the App
Save the script in a file, let's say multi_page_app.py, and run it using
streamlit run multi_page_app.py
This will open a new tab in your browser with the Streamlit app.
Navigating Between Pages
The navigation is facilitated through the Streamlit sidebar. Users can select different pages from the sidebar to view relevant content.
.
.
Thank You..!!! ??
Senior Engineer | UG | Junior Research fellow ??
1 年Thanks for posting