Hello Everyone
I am creating a Streamlit app where I want to add a button which should take a user to another page. I tried some examples but all of them have sidebar coming up. I don’t want a sidebar in my app. Please help me implementing this solution. Also the solution should work on Streamlit Cloud. Thank you.
Hi @AhXaN,
Thanks for sharing this question!
Make sure to use the initial_sidebar_state="collapsed"
keyword in st.set_page_config()
. See docs st.set_page_config - Streamlit Docs.
Here’s an example of code for switching pages using st.switch_page`:
# List of pages
pages = {
"🎡 Scroll container": "./pages/2_🎡_Scroll_container.py",
"❓ st.query⚊params": "./pages/3_❓_st.query⚊params.py",
"📄 st.switch⚊pages": "./pages/4_📄_st.switch⚊pages.py",
"🔗 Link column formatting": "./pages/5_🔗_Link_column_formatting.py"
}
# Dropdown to select the page
selected_page = st.selectbox("Select a page:", list(pages.keys()))
# Button to switch page
switch_page = st.button("Switch page")
if switch_page:
# Switch to the selected page
page_file = pages[selected_page]
st.switch_page(page_file)
import streamlit as st
page=st.session_state
'''if there is no page automatically calls main'''
if "currentPage" not in page:
page["currentPage"]="main"
if page["currentPage"]=="main":
st.header("You are at main page")
changePage=st.button("nextPage")
if changePage:
page["currentPage"]="secondPage"
st.experimental_rerun()
if page["currentPage"]=="secondPage":
st.header("You are at Second page")
back=st.button("move back")
if back:
''' moving to main page '''
page["currentPage"]="main"
st.experimental_rerun()Preformatted text
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.