Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,82 @@
|
|
1 |
import streamlit as st
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# --- SHARED ON ALL PAGES ---
|
5 |
#st.logo(image="images/menu_book_60dp_75FBFD.png")
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
+
import time
|
4 |
+
|
5 |
+
# --- Custom CSS ---
|
6 |
+
# !!! IMPORTANT !!!
|
7 |
+
# 1. YOU MUST VERIFY AND ADJUST THE SELECTORS BELOW USING YOUR BROWSER'S INSPECTOR.
|
8 |
+
# 2. THE HEADER_HEIGHT MUST ACCURATELY REFLECT YOUR HEADER'S ACTUAL HEIGHT.
|
9 |
+
|
10 |
+
# Use the developer tools to find your header's actual height.
|
11 |
+
# Inspect the header element, go to the "Computed" tab in styles, and find its height.
|
12 |
+
HEADER_HEIGHT = "60px" # EXAMPLE: Adjust this (e.g., "56px", "4rem")
|
13 |
+
|
14 |
+
# ---- SELECTOR FOR THE HEADER ----
|
15 |
+
# Try this first (common for recent Streamlit versions):
|
16 |
+
HEADER_SELECTOR = 'header[data-testid="stHeader"]'
|
17 |
+
# If that doesn't work, inspect and find the correct one.
|
18 |
+
# It might be just 'header', or a div with a specific class.
|
19 |
+
# Example if using a class: HEADER_SELECTOR = 'div.my-custom-looking-header-class'
|
20 |
+
|
21 |
+
# ---- SELECTOR FOR THE MAIN CONTENT AREA THAT NEEDS PADDING ----
|
22 |
+
# This targets the first direct div child of the stAppViewContainer,
|
23 |
+
# which often holds the main scrollable content.
|
24 |
+
MAIN_CONTENT_SELECTOR = 'section[data-testid="stMainBlockContainer"] > div:nth-child(1)'
|
25 |
+
# Alternative if the above doesn't work or if your content is further nested:
|
26 |
+
# MAIN_CONTENT_SELECTOR = 'section[data-testid="stAppViewContainer"] .main-content-wrapper-class'
|
27 |
+
# Or, very commonly, Streamlit wraps main content in a div with class "block-container":
|
28 |
+
# MAIN_CONTENT_SELECTOR = 'section[data-testid="stAppViewContainer"] .block-container'
|
29 |
+
# MAIN_CONTENT_SELECTOR = '.main .block-container' # A more general selector for block-container
|
30 |
+
|
31 |
+
custom_css = f"""
|
32 |
+
<style>
|
33 |
+
/* Making the Streamlit header sticky */
|
34 |
+
{HEADER_SELECTOR} {{
|
35 |
+
position: -webkit-sticky !important; /* For Safari */
|
36 |
+
position: sticky !important;
|
37 |
+
top: 0 !important;
|
38 |
+
z-index: 9999 !important; /* Very high z-index */
|
39 |
+
background-color: #0f1116 !important; /* Or your app's header background color */
|
40 |
+
/* Add a subtle shadow to make it feel more distinct when content scrolls under */
|
41 |
+
/* box-shadow: 0 2px 4px -1px rgba(0,0,0,0.1); */
|
42 |
+
}}
|
43 |
+
|
44 |
+
/* Adding padding to the main content area to prevent overlap with the sticky header */
|
45 |
+
{MAIN_CONTENT_SELECTOR} {{
|
46 |
+
padding-top: {HEADER_HEIGHT} !important;
|
47 |
+
}}
|
48 |
+
|
49 |
+
/* Optional: If your app is set to wide mode and the header isn't spanning full width */
|
50 |
+
/* This might be needed if the sticky positioning affects its width calculation. */
|
51 |
+
/*
|
52 |
+
{HEADER_SELECTOR} {{
|
53 |
+
width: 100% !important;
|
54 |
+
}}
|
55 |
+
*/
|
56 |
+
</style>
|
57 |
+
"""
|
58 |
+
|
59 |
+
# Inject CSS as early as possible in your app
|
60 |
+
st.markdown(custom_css, unsafe_allow_html=True)
|
61 |
+
|
62 |
+
# --- Your Streamlit App ---
|
63 |
+
st.title("App with Attempted Sticky Header")
|
64 |
+
st.sidebar.header("Sidebar")
|
65 |
+
st.sidebar.write("Sidebar content here.")
|
66 |
+
|
67 |
+
st.header("Main Content Section")
|
68 |
+
st.write(f"The header should be sticky. This content section has a top padding of approximately {HEADER_HEIGHT} to compensate for the header.")
|
69 |
+
st.info(f"Header Selector Used: `{HEADER_SELECTOR}`")
|
70 |
+
st.info(f"Main Content Selector Used: `{MAIN_CONTENT_SELECTOR}`")
|
71 |
+
|
72 |
+
|
73 |
+
if st.button("Run Process (for status widget)"):
|
74 |
+
with st.spinner("Processing..."):
|
75 |
+
time.sleep(2)
|
76 |
+
st.success("Process finished!")
|
77 |
+
|
78 |
+
for i in range(60):
|
79 |
+
st.write(f"Scrollable line of content {i + 1}.")
|
80 |
|
81 |
# --- SHARED ON ALL PAGES ---
|
82 |
#st.logo(image="images/menu_book_60dp_75FBFD.png")
|