Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -57,6 +57,7 @@ footer {
|
|
| 57 |
width: 20rem;
|
| 58 |
overflow-y: auto !important;
|
| 59 |
z-index: 99999;
|
|
|
|
| 60 |
}
|
| 61 |
[data-testid="stSidebar"]::-webkit-scrollbar {
|
| 62 |
width: 6px;
|
|
@@ -156,9 +157,172 @@ section[data-testid="stFileUploader"] small {
|
|
| 156 |
border: none;
|
| 157 |
padding: 0;
|
| 158 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
</style>
|
| 160 |
""", unsafe_allow_html=True)
|
| 161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
# ---------------- FIXED HEADER ----------------
|
| 163 |
st.markdown("""
|
| 164 |
<div class="fixed-header">
|
|
|
|
| 57 |
width: 20rem;
|
| 58 |
overflow-y: auto !important;
|
| 59 |
z-index: 99999;
|
| 60 |
+
transition: transform 0.3s ease;
|
| 61 |
}
|
| 62 |
[data-testid="stSidebar"]::-webkit-scrollbar {
|
| 63 |
width: 6px;
|
|
|
|
| 157 |
border: none;
|
| 158 |
padding: 0;
|
| 159 |
}
|
| 160 |
+
/* 11. EXPAND SIDEBAR BUTTON */
|
| 161 |
+
.expand-sidebar-btn {
|
| 162 |
+
position: fixed;
|
| 163 |
+
top: 1rem;
|
| 164 |
+
left: 1rem;
|
| 165 |
+
z-index: 999999;
|
| 166 |
+
background: #1e3a8a;
|
| 167 |
+
color: white;
|
| 168 |
+
border: none;
|
| 169 |
+
border-radius: 50%;
|
| 170 |
+
width: 50px;
|
| 171 |
+
height: 50px;
|
| 172 |
+
font-size: 1.5rem;
|
| 173 |
+
cursor: pointer;
|
| 174 |
+
display: none;
|
| 175 |
+
align-items: center;
|
| 176 |
+
justify-content: center;
|
| 177 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
| 178 |
+
transition: all 0.3s ease;
|
| 179 |
+
opacity: 0.9;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
.expand-sidebar-btn:hover {
|
| 183 |
+
background: #2563eb;
|
| 184 |
+
transform: scale(1.1);
|
| 185 |
+
opacity: 1;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
/* 12. SIDEBAR CLOSE BUTTON CUSTOMIZATION */
|
| 189 |
+
[data-testid="stSidebar"] [data-testid="baseButton-headerNoPadding"] {
|
| 190 |
+
position: absolute;
|
| 191 |
+
top: 0.75rem;
|
| 192 |
+
right: 0.75rem;
|
| 193 |
+
z-index: 100000;
|
| 194 |
+
background: transparent;
|
| 195 |
+
color: #ccc;
|
| 196 |
+
border: none;
|
| 197 |
+
font-size: 1.2rem;
|
| 198 |
+
padding: 4px 8px;
|
| 199 |
+
border-radius: 4px;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
[data-testid="stSidebar"] [data-testid="baseButton-headerNoPadding"]:hover {
|
| 203 |
+
background: rgba(255, 255, 255, 0.1);
|
| 204 |
+
color: white;
|
| 205 |
+
}
|
| 206 |
</style>
|
| 207 |
""", unsafe_allow_html=True)
|
| 208 |
|
| 209 |
+
# ---------------- SIDEBAR EXPAND BUTTON JAVASCRIPT ----------------
|
| 210 |
+
st.markdown("""
|
| 211 |
+
<div id="expandSidebarBtn" class="expand-sidebar-btn" title="Expand Sidebar">☰</div>
|
| 212 |
+
|
| 213 |
+
<script>
|
| 214 |
+
// Function to check if sidebar is collapsed
|
| 215 |
+
function isSidebarCollapsed() {
|
| 216 |
+
const sidebar = document.querySelector('[data-testid="stSidebar"]');
|
| 217 |
+
if (!sidebar) return true;
|
| 218 |
+
|
| 219 |
+
// Check various indicators of collapsed sidebar
|
| 220 |
+
const computedStyle = window.getComputedStyle(sidebar);
|
| 221 |
+
const isHidden = computedStyle.transform === 'matrix(1, 0, 0, 1, -320, 0)' ||
|
| 222 |
+
computedStyle.display === 'none' ||
|
| 223 |
+
computedStyle.visibility === 'hidden' ||
|
| 224 |
+
sidebar.offsetWidth === 0 ||
|
| 225 |
+
sidebar.style.transform === 'translateX(-320px)' ||
|
| 226 |
+
sidebar.style.transform === 'translateX(-100%)';
|
| 227 |
+
|
| 228 |
+
return isHidden;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
// Function to expand the sidebar
|
| 232 |
+
function expandSidebar() {
|
| 233 |
+
const sidebar = document.querySelector('[data-testid="stSidebar"]');
|
| 234 |
+
const expandBtn = document.getElementById('expandSidebarBtn');
|
| 235 |
+
|
| 236 |
+
if (sidebar) {
|
| 237 |
+
// Remove any hiding transforms
|
| 238 |
+
sidebar.style.transform = 'translateX(0)';
|
| 239 |
+
sidebar.style.display = 'block';
|
| 240 |
+
sidebar.style.visibility = 'visible';
|
| 241 |
+
|
| 242 |
+
// Trigger Streamlit's internal sidebar show mechanism
|
| 243 |
+
const event = new Event('sidebarStateChange');
|
| 244 |
+
window.dispatchEvent(event);
|
| 245 |
+
|
| 246 |
+
// Hide the expand button
|
| 247 |
+
if (expandBtn) {
|
| 248 |
+
expandBtn.style.display = 'none';
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
console.log('Sidebar expanded');
|
| 252 |
+
}
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
// Function to update expand button visibility
|
| 256 |
+
function updateExpandButton() {
|
| 257 |
+
const expandBtn = document.getElementById('expandSidebarBtn');
|
| 258 |
+
if (!expandBtn) return;
|
| 259 |
+
|
| 260 |
+
if (isSidebarCollapsed()) {
|
| 261 |
+
expandBtn.style.display = 'flex';
|
| 262 |
+
} else {
|
| 263 |
+
expandBtn.style.display = 'none';
|
| 264 |
+
}
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
// Initialize when DOM is loaded
|
| 268 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 269 |
+
// Create expand button if it doesn't exist
|
| 270 |
+
if (!document.getElementById('expandSidebarBtn')) {
|
| 271 |
+
const btn = document.createElement('div');
|
| 272 |
+
btn.id = 'expandSidebarBtn';
|
| 273 |
+
btn.className = 'expand-sidebar-btn';
|
| 274 |
+
btn.title = 'Expand Sidebar';
|
| 275 |
+
btn.innerHTML = '☰';
|
| 276 |
+
btn.addEventListener('click', expandSidebar);
|
| 277 |
+
document.body.appendChild(btn);
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
// Add click event to existing button
|
| 281 |
+
const expandBtn = document.getElementById('expandSidebarBtn');
|
| 282 |
+
if (expandBtn) {
|
| 283 |
+
expandBtn.addEventListener('click', expandSidebar);
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
// Initial check
|
| 287 |
+
updateExpandButton();
|
| 288 |
+
|
| 289 |
+
// Set up interval to check sidebar state
|
| 290 |
+
setInterval(updateExpandButton, 500);
|
| 291 |
+
|
| 292 |
+
// Also check on window resize and scroll
|
| 293 |
+
window.addEventListener('resize', updateExpandButton);
|
| 294 |
+
window.addEventListener('scroll', updateExpandButton);
|
| 295 |
+
|
| 296 |
+
// Observe DOM changes for sidebar state
|
| 297 |
+
const observer = new MutationObserver(function(mutations) {
|
| 298 |
+
mutations.forEach(function(mutation) {
|
| 299 |
+
if (mutation.type === 'attributes' &&
|
| 300 |
+
mutation.target.hasAttribute('data-testid') &&
|
| 301 |
+
mutation.target.getAttribute('data-testid') === 'stSidebar') {
|
| 302 |
+
updateExpandButton();
|
| 303 |
+
}
|
| 304 |
+
});
|
| 305 |
+
});
|
| 306 |
+
|
| 307 |
+
const sidebar = document.querySelector('[data-testid="stSidebar"]');
|
| 308 |
+
if (sidebar) {
|
| 309 |
+
observer.observe(sidebar, { attributes: true });
|
| 310 |
+
}
|
| 311 |
+
});
|
| 312 |
+
|
| 313 |
+
// Override Streamlit's sidebar close behavior to show our button
|
| 314 |
+
document.addEventListener('click', function(e) {
|
| 315 |
+
// Check if click is on sidebar close button
|
| 316 |
+
if (e.target.closest('[data-testid="baseButton-headerNoPadding"]')) {
|
| 317 |
+
// Show our expand button after a short delay
|
| 318 |
+
setTimeout(() => {
|
| 319 |
+
updateExpandButton();
|
| 320 |
+
}, 100);
|
| 321 |
+
}
|
| 322 |
+
});
|
| 323 |
+
</script>
|
| 324 |
+
""", unsafe_allow_html=True)
|
| 325 |
+
|
| 326 |
# ---------------- FIXED HEADER ----------------
|
| 327 |
st.markdown("""
|
| 328 |
<div class="fixed-header">
|