Way to change the page_config on mobile

I have set the layout of my page to wide.
Is there a way to change the layout to centered when accessed by a mobile? The reason is because my plotly graphs are being displayed very narrow when in wide mode on a mobile. On a PC they are just fine.

Hi @R_D :wave:

I don’t think there’s an official programmatic way to detect that the app is being accessed on a mobile and consequently change the layout to centered. Your users would have to click the Hamburger menu icon → Settings → Uncheck Wide mode.

I’ll defer to the community if there are hacks to achieve this.

The only other way I can think of is to let the user specify if they’re viewing the app on a mobile and, if so, to update the layout using session state:

import streamlit as st

if "center" not in st.session_state:
    layout = "wide"
else:
    layout = "centered" if st.session_state.center else "wide"

st.set_page_config(layout=layout)

st.checkbox(
    "Viewing on a mobile?", key="center", value=st.session_state.get("center", False)
)

mobile-layout-dynamic

Snehan :balloon:

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.