Hello Streamlit Community,
I am developing an application where I would like to provide the users with the flexibility to switch between the default layout and wide screen mode dynamically, based on their preference. I understand that st.set_page_config()
must be called at the beginning of the script and that it cannot be used to change the layout once the app has started running. However, I am looking for a way to integrate a sidebar toggle to switch to wide screen mode without restarting the app manually.
Here’s what I have tried so far:
Check if ‘wide_mode’ is already in the session state
if ‘wide_mode’ not in st.session_state:
# Initialize it with a default value
st.session_state[‘wide_mode’] = False
Set the page config based on the current value of ‘wide_mode’
st.set_page_config(page_title=“Your App”, layout=“wide” if st.session_state[‘wide_mode’] else “centered”)
Sidebar checkbox to toggle the wide mode
st.sidebar.checkbox(“Wide mode”, value=st.session_state[‘wide_mode’], on_change=lambda: st.experimental_rerun())
This approach requires the user to refresh the page to see the changes, which is not the most seamless experience I want to offer.
- Is there a way to programmatically toggle the wide screen mode without needing a full page refresh?
- Can the layout be changed dynamically with a sidebar control in the current version of Streamlit, or is there a workaround that you would suggest?
- If it is not possible, could this be considered a feature request for future versions of Streamlit?
Any insights, suggestions, or workarounds would be greatly appreciated. Thank you for your time and help!