|
import streamlit as st |
|
|
|
import time |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HEADER_HEIGHT = "60px" |
|
|
|
|
|
|
|
HEADER_SELECTOR = 'header[data-testid="stHeader"]' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MAIN_CONTENT_SELECTOR = 'section[data-testid="stAppViewContainer"] .block-container' |
|
|
|
|
|
custom_css = f""" |
|
<style> |
|
/* Making the Streamlit header sticky */ |
|
{HEADER_SELECTOR} {{ |
|
position: -webkit-sticky !important; /* For Safari */ |
|
position: sticky !important; |
|
top: 0 !important; |
|
z-index: 9999 !important; /* Very high z-index */ |
|
background-color: #90EE90 !important; /* Or your app's header background color */ |
|
/* Add a subtle shadow to make it feel more distinct when content scrolls under */ |
|
/* box-shadow: 0 2px 4px -1px rgba(0,0,0,0.1); */ |
|
}} |
|
|
|
/* Adding padding to the main content area to prevent overlap with the sticky header */ |
|
{MAIN_CONTENT_SELECTOR} {{ |
|
padding-top: {HEADER_HEIGHT} !important; |
|
background-color: red !important; |
|
border-style: solid !important; |
|
border-color: red !important; |
|
}} |
|
|
|
/* Optional: If your app is set to wide mode and the header isn't spanning full width */ |
|
/* This might be needed if the sticky positioning affects its width calculation. */ |
|
/* |
|
{HEADER_SELECTOR} {{ |
|
width: 100% !important; |
|
}} |
|
*/ |
|
</style> |
|
""" |
|
|
|
|
|
st.markdown(custom_css, unsafe_allow_html=True) |
|
|
|
|
|
st.title("App with Attempted Sticky Header") |
|
st.sidebar.header("Sidebar") |
|
st.sidebar.write("Sidebar content here.") |
|
|
|
st.header("Main Content Section") |
|
st.write(f"The header should be sticky. This content section has a top padding of approximately {HEADER_HEIGHT} to compensate for the header.") |
|
st.info(f"Header Selector Used: `{HEADER_SELECTOR}`") |
|
st.info(f"Main Content Selector Used: `{MAIN_CONTENT_SELECTOR}`") |
|
|
|
|
|
if st.button("Run Process (for status widget)"): |
|
with st.spinner("Processing..."): |
|
time.sleep(2) |
|
st.success("Process finished!") |
|
|
|
for i in range(60): |
|
st.write(f"Scrollable line of content {i + 1}.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type_text_page = st.Page( |
|
page="pages/type_text.py", |
|
title="DEMO (work in progress)", |
|
icon=":material/keyboard:", |
|
default=True,) |
|
|
|
|
|
pg = st.navigation(pages=[type_text_page]) |
|
|
|
pg.run() |