georad commited on
Commit
4b8ff6b
·
verified ·
1 Parent(s): 163f691

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -0
app.py CHANGED
@@ -1,5 +1,76 @@
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
+ # WARNING: These selectors might change with Streamlit versions.
7
+ # Always inspect your app's HTML structure to confirm them.
8
+
9
+ # It's crucial to estimate or dynamically get the header's height.
10
+ # For this example, we'll assume a fixed header height (e.g., 3.5rem or 56px).
11
+ # You might need to adjust this value based on your Streamlit version and app title length.
12
+ HEADER_HEIGHT = "60px" # Adjust this value as needed
13
+
14
+ custom_css = f"""
15
+ <style>
16
+ /* Target the Streamlit header */
17
+ header[data-testid="stHeader"] {{
18
+ position: sticky !important;
19
+ top: 0 !important;
20
+ z-index: 1000 !important; /* High z-index to keep it on top */
21
+ background-color: #0F1116 !important; /* Match Streamlit's dark theme header or your preference */
22
+ /* If your header background is transparent or semi-transparent by default,
23
+ ensure you set a solid color to prevent content from showing through. */
24
+ }}
25
+
26
+ /* Target the main app view container to add padding AFTER the header */
27
+ /* This selector targets the container that holds the main page content */
28
+ section[data-testid="stAppViewContainer"] > div:first-child {{
29
+ padding-top: {HEADER_HEIGHT} !important;
30
+ }}
31
+
32
+ /* Fallback for older Streamlit versions or different structures if the above doesn't work.
33
+ You might need to find a more specific selector for the main content wrapper.
34
+ For example, some apps might be wrapped in a div directly under `section.main`.
35
+ */
36
+ /*
37
+ .main .block-container {{
38
+ padding-top: {HEADER_HEIGHT} !important;
39
+ }}
40
+ */
41
+
42
+ /* Ensure the sidebar scrolling is independent if needed,
43
+ though typically it is already. */
44
+ /*
45
+ section[data-testid="stSidebar"] {{
46
+ top: 0px; // If you want sidebar to also respect top
47
+ }}
48
+ */
49
+ </style>
50
+ """
51
+ st.markdown(custom_css, unsafe_allow_html=True)
52
+
53
+ # --- Your Streamlit App ---
54
+ st.title("Sticky Header App")
55
+ st.sidebar.header("Sidebar Content")
56
+ st.sidebar.write("This sidebar should scroll independently.")
57
+ for i in range(5):
58
+ st.sidebar.write(f"Sidebar Item {i+1}")
59
+
60
+
61
+ st.header("Main Application Content")
62
+ st.write(f"The header above should remain sticky. The top padding of this content section has been adjusted by approximately {HEADER_HEIGHT}.")
63
+
64
+ if st.button("Simulate Work (triggers status widget)"):
65
+ with st.spinner("Processing... Please wait."):
66
+ time.sleep(3)
67
+ st.success("Done!")
68
+
69
+ for i in range(50):
70
+ st.write(f"Scrollable content line {i + 1}.")
71
+
72
+ st.info(f"Current Date/Time in Al Khobar: {time.strftime('%Y-%m-%d %H:%M:%S %Z', time.localtime())} (Note: This is server time if deployed, or local time if run locally. Hugging Face Spaces run on UTC.)")
73
+ st.warning("Remember: The CSS selectors used here for the header and main content might change with Streamlit updates. You may need to re-inspect and adjust them.")
74
 
75
  # --- SHARED ON ALL PAGES ---
76
  st.logo(image="images/menu_book_60dp_75FBFD.png")