Update app.py
Browse files
app.py
CHANGED
@@ -1,149 +1,18 @@
|
|
1 |
import streamlit as st
|
2 |
|
3 |
-
#
|
4 |
-
|
5 |
-
custom_css = """
|
6 |
<style>
|
7 |
-
/*
|
8 |
-
header[data-testid="stHeader"]
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
right: 0 !important;
|
15 |
-
width: 100vw !important;
|
16 |
-
z-index: 999999 !important;
|
17 |
-
background-color: #90EE90 !important;
|
18 |
-
box-shadow: 0 1px 5px rgba(0,0,0,0.1) !important;
|
19 |
-
min-height: 60px !important;
|
20 |
-
}
|
21 |
-
|
22 |
-
/* Adjust main content to prevent overlap with fixed header */
|
23 |
-
section[data-testid="stMain"],
|
24 |
-
.main .block-container,
|
25 |
-
div[data-testid="stDecoratedAppViewContainer"] div[data-testid="stAppViewContainer"] {
|
26 |
-
padding-top: 70px !important; /* Match your header height + some extra space */
|
27 |
-
margin-top: 10px !important;
|
28 |
-
}
|
29 |
-
|
30 |
-
/* Target the root element in Hugging Face environment */
|
31 |
-
#root {
|
32 |
-
position: relative !important;
|
33 |
-
}
|
34 |
-
|
35 |
-
/* Make the iframe itself handle scrolling properly */
|
36 |
-
#streamlit-iframe {
|
37 |
-
overflow: auto !important;
|
38 |
-
height: 100vh !important;
|
39 |
-
}
|
40 |
-
|
41 |
-
/* Handle outer scrollbar scenario */
|
42 |
-
body {
|
43 |
-
overflow: auto !important;
|
44 |
-
}
|
45 |
-
|
46 |
-
/* Target both inner and outer scroll containers */
|
47 |
-
.stApp,
|
48 |
-
div[data-testid="stAppViewBlockContainer"],
|
49 |
-
div.streamlit-container,
|
50 |
-
div[data-testid="stDecoratedAppViewContainer"] {
|
51 |
-
position: relative !important;
|
52 |
-
padding-top: 0 !important;
|
53 |
-
}
|
54 |
-
|
55 |
-
/* Fix for Hugging Face specific container */
|
56 |
-
.st-emotion-cache-lrlib {
|
57 |
-
padding-top: 60px !important;
|
58 |
-
}
|
59 |
-
|
60 |
-
/* Handle any custom scrollable containers */
|
61 |
-
div.streamlit-container {
|
62 |
-
overflow: visible !important;
|
63 |
-
}
|
64 |
-
|
65 |
-
/* Ensure header remains visible with outside scrollbar */
|
66 |
-
body.hf-w-body .stApp {
|
67 |
-
padding-top: 0 !important;
|
68 |
-
}
|
69 |
-
|
70 |
-
/* Target Hugging Face's specific elements */
|
71 |
-
.gradient-border-wrap {
|
72 |
-
margin-top: 60px !important;
|
73 |
}
|
74 |
</style>
|
75 |
-
"""
|
76 |
-
|
77 |
-
# Enhanced JavaScript for complete handling of both scrollbar scenarios
|
78 |
-
js_fix = """
|
79 |
-
<script>
|
80 |
-
// This script ensures the header stays fixed in both scrollbar scenarios
|
81 |
-
window.addEventListener('DOMContentLoaded', (event) => {
|
82 |
-
// Function to apply header fixing
|
83 |
-
const fixHeader = () => {
|
84 |
-
// Target the header
|
85 |
-
const header = document.querySelector('header[data-testid="stHeader"]');
|
86 |
-
if (header) {
|
87 |
-
// Make it fixed
|
88 |
-
header.style.position = 'fixed';
|
89 |
-
header.style.top = '0';
|
90 |
-
header.style.zIndex = '999999';
|
91 |
-
header.style.width = '100%';
|
92 |
-
header.style.backgroundColor = '#90EE90';
|
93 |
-
header.style.minHeight = '60px';
|
94 |
-
|
95 |
-
// Add padding to main content (multiple selectors)
|
96 |
-
const mainContainers = [
|
97 |
-
document.querySelector('section[data-testid="stMain"]'),
|
98 |
-
document.querySelector('.main .block-container'),
|
99 |
-
document.querySelector('div[data-testid="stAppViewContainer"]'),
|
100 |
-
document.querySelector('div.streamlit-container')
|
101 |
-
];
|
102 |
-
|
103 |
-
mainContainers.forEach(container => {
|
104 |
-
if (container) {
|
105 |
-
container.style.paddingTop = '70px';
|
106 |
-
}
|
107 |
-
});
|
108 |
-
|
109 |
-
// Handle outer scrollbar - make sure header is visible
|
110 |
-
const outerScroll = () => {
|
111 |
-
const scrollY = window.scrollY || window.pageYOffset;
|
112 |
-
if (scrollY > 0) {
|
113 |
-
header.style.top = scrollY + 'px';
|
114 |
-
} else {
|
115 |
-
header.style.top = '0';
|
116 |
-
}
|
117 |
-
};
|
118 |
-
|
119 |
-
// Apply to both window and any iframe parent
|
120 |
-
window.addEventListener('scroll', outerScroll);
|
121 |
-
if (window.parent && window.parent !== window) {
|
122 |
-
try {
|
123 |
-
window.parent.addEventListener('scroll', outerScroll);
|
124 |
-
} catch (e) {
|
125 |
-
// Cross-origin issues might prevent this
|
126 |
-
console.log('Could not attach to parent scroll');
|
127 |
-
}
|
128 |
-
}
|
129 |
-
}
|
130 |
-
};
|
131 |
-
|
132 |
-
// Apply immediately
|
133 |
-
fixHeader();
|
134 |
-
|
135 |
-
// And again after a short delay to ensure all elements are loaded
|
136 |
-
setTimeout(fixHeader, 500);
|
137 |
-
|
138 |
-
// And one more time after everything is definitely loaded
|
139 |
-
setTimeout(fixHeader, 2000);
|
140 |
-
});
|
141 |
-
</script>
|
142 |
-
"""
|
143 |
-
|
144 |
-
# Inject CSS and JS as early as possible in your app
|
145 |
-
st.markdown(custom_css, unsafe_allow_html=True)
|
146 |
-
st.markdown(js_fix, unsafe_allow_html=True)
|
147 |
|
148 |
# --- PAGE SETUP ---
|
149 |
type_text_page = st.Page(
|
@@ -163,3 +32,4 @@ st.sidebar.text("Demo by JA-RAD")
|
|
163 |
# --- NAVIGATION SETUP ---
|
164 |
pg = st.navigation(pages=[type_text_page]) # WITHOUT SECTIONS
|
165 |
pg.run()
|
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
+
# Simpler, more reliable sticky header implementation
|
4 |
+
st.markdown("""
|
|
|
5 |
<style>
|
6 |
+
/* Basic sticky header */
|
7 |
+
header[data-testid="stHeader"] {
|
8 |
+
position: sticky;
|
9 |
+
top: 0;
|
10 |
+
background-color: #90EE90;
|
11 |
+
z-index: 999;
|
12 |
+
height: auto;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
}
|
14 |
</style>
|
15 |
+
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# --- PAGE SETUP ---
|
18 |
type_text_page = st.Page(
|
|
|
32 |
# --- NAVIGATION SETUP ---
|
33 |
pg = st.navigation(pages=[type_text_page]) # WITHOUT SECTIONS
|
34 |
pg.run()
|
35 |
+
|