Unwanted content from previous page appears faded in the background of new page

When I click onto a new page or tab, the content of the previous page or tab appears faded in the background, or sometimes underneath the content of the new page, and doesn’t go away. How can I stop this? I’ve tried using st.empty() and containers - but this hasn’t addressed the issue. Would be ideal if when you switch a page you only see the content of the new page against a blank, opaque background.

Can you post a minimal reproducible code?

Hello @T_lea,

When switching pages, make sure to clear or replace the entire page content:

import streamlit as st

# Option for navigation
page = st.sidebar.selectbox("Choose a page", ["Home", "Page 2"])

# Container for page content
content = st.container()

# Clear previous content
content.empty()

# Depending on the page, display new content in the same container
with content:
    if page == "Home":
        st.write("This is the home page.")
    elif page == "Page 2":
        st.write("This is page 2.")

Hope this helps!

Kind Regards,
Sahir Maharaj
Data Scientist | AI Engineer

P.S. Lets connect on LinkedIn!

➤ Want me to build your solution? Lets chat about how I can assist!
➤ Join my Medium community of 30k readers! Sharing my knowledge about data science and AI
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ 100+ FREE Power BI Themes: Download Now

3 Likes