I know that the st.set_page_config function can only be called once in a Streamlit, but is there any workaround to be able to have a page with the layout wide and the another with layout centered?
Thus, in the following I pretended that the introduction page to be wide, but the conclusion to be centered:
import streamlit as st
st.set_page_config(
page_title='Streamlit Page',
layout='wide', #layout='centered'
initial_sidebar_state='expanded',
)
# Sidebar navigation
selected_page = st.sidebar.selectbox(
'Select page',
options=[
'Introduction',
'Conclusion',
# 'About',
])
if selected_page == 'Introduction':
st.text("Welcome to this Page")
elif selected_page == 'Conclusion':
st.text("This is the conclusion page")
import streamlit as st
from streamlit import session_state as ss
# Declare and initialize the layout session variable.
if 'layout' not in ss:
ss.layout = 'wide'
# The layout parameter will receive the value of layout session variable.
st.set_page_config(
page_title='Streamlit Page',
layout=ss.layout,
initial_sidebar_state='expanded',
)
def layout_change_cb():
"""Called when there is a change in selectbox.
The value of selectbox is stored in ss.selpagek.
Depending on the value, we will change the layout session variable
value to either wide or centered.
"""
if ss.selpagek == 'Introduction':
ss.layout = 'wide'
else:
ss.layout = 'centered'
# Sidebar navigation
st.sidebar.selectbox(
'Select page',
options=[
'Introduction',
'Conclusion'
],
key='selpagek',
on_change=layout_change_cb # callback
)
if ss.selpagek == 'Introduction':
st.text("Welcome to this Page")
elif ss.selpagek == 'Conclusion':
st.text("This is the conclusion page")
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.