Update app.py
Browse files
app.py
CHANGED
@@ -1,58 +1,35 @@
|
|
1 |
import streamlit as st
|
2 |
|
3 |
-
#
|
4 |
-
|
5 |
-
HEADER_SELECTOR = 'header[data-testid="stHeader"]'
|
6 |
-
|
7 |
-
# ---- SELECTOR FOR THE MAIN CONTENT AREA THAT NEEDS PADDING ----
|
8 |
-
# Target the first direct div child of the stAppViewContainer which often holds the main scrollable content
|
9 |
-
MAIN_CONTENT_SELECTOR = 'section[data-testid="stMain"]'
|
10 |
-
#MAIN_CONTENT_SELECTOR = 'section[data-testid="stMain"] > div:nth-child(1)'
|
11 |
-
#MAIN_CONTENT_SELECTOR = 'section[data-testid="stMainBlockContainer"]'
|
12 |
-
#MAIN_CONTENT_SELECTOR = 'section[data-testid="stAppViewContainer"]'
|
13 |
-
#MAIN_CONTENT_SELECTOR = 'section[data-testid="stAppViewContainer"] > div:nth-child(1)'
|
14 |
-
# Alternative if the above doesn't work or if your content is further nested:
|
15 |
-
#MAIN_CONTENT_SELECTOR = 'section[data-testid="stAppViewContainer"] .main-content-wrapper-class'
|
16 |
-
# Or, very commonly, Streamlit wraps main content in a div with class "block-container":
|
17 |
-
#MAIN_CONTENT_SELECTOR = 'section[data-testid="stAppViewContainer"] .block-container'
|
18 |
-
#MAIN_CONTENT_SELECTOR = '.main .block-container' # A more general selector for block-container
|
19 |
-
|
20 |
-
custom_css = f"""
|
21 |
<style>
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
}
|
43 |
-
|
44 |
-
/* Optional: If your app is set to wide mode and the header isn't spanning full width */
|
45 |
-
/* This might be needed if the sticky positioning affects its width calculation. */
|
46 |
-
/*
|
47 |
-
#{HEADER_SELECTOR} {{
|
48 |
-
# width: 100% !important;
|
49 |
-
#}}
|
50 |
-
#*/
|
51 |
</style>
|
52 |
-
"""
|
53 |
|
54 |
-
#
|
55 |
-
st.
|
|
|
56 |
|
57 |
# --- PAGE SETUP ---
|
58 |
type_text_page = st.Page(
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
+
# Custom CSS for sticky header
|
4 |
+
st.markdown("""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
<style>
|
6 |
+
.stApp header {
|
7 |
+
position: fixed;
|
8 |
+
top: 0;
|
9 |
+
z-index: 999;
|
10 |
+
background-color: white;
|
11 |
+
width: 100%;
|
12 |
+
}
|
13 |
+
|
14 |
+
/* Add padding to the main content to prevent it from being hidden under the fixed header */
|
15 |
+
.main .block-container {
|
16 |
+
padding-top: 5rem;
|
17 |
+
}
|
18 |
+
|
19 |
+
/* Additional CSS to ensure compatibility with Hugging Face iframe embedding */
|
20 |
+
.stApp {
|
21 |
+
overflow: auto;
|
22 |
+
}
|
23 |
+
|
24 |
+
div[data-testid="stVerticalBlock"] {
|
25 |
+
padding-top: 1rem;
|
26 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
</style>
|
28 |
+
""", unsafe_allow_html=True)
|
29 |
|
30 |
+
# Your app content
|
31 |
+
st.title("My App with Sticky Header")
|
32 |
+
# Rest of your app...
|
33 |
|
34 |
# --- PAGE SETUP ---
|
35 |
type_text_page = st.Page(
|