Update app.py
Browse files
app.py
CHANGED
@@ -29,6 +29,48 @@ def add_sticky_header_css():
|
|
29 |
</style>
|
30 |
""", unsafe_allow_html=True)
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
# At the start of main function or execution flow
|
33 |
add_sticky_header_css()
|
34 |
|
|
|
29 |
</style>
|
30 |
""", unsafe_allow_html=True)
|
31 |
|
32 |
+
def scroll_to_bottom():
|
33 |
+
# This script uses Streamlit's message system to ensure proper timing
|
34 |
+
js_code = """
|
35 |
+
<script>
|
36 |
+
// Function to scroll to bottom
|
37 |
+
function scrollToBottom() {
|
38 |
+
// This targets Streamlit's specific structure
|
39 |
+
const mainContainer = window.parent.document.querySelector('.stApp');
|
40 |
+
if (mainContainer) {
|
41 |
+
mainContainer.scrollTo({
|
42 |
+
top: mainContainer.scrollHeight,
|
43 |
+
behavior: 'smooth'
|
44 |
+
});
|
45 |
+
}
|
46 |
+
}
|
47 |
+
|
48 |
+
// Use MutationObserver to detect when content is added
|
49 |
+
const observer = new MutationObserver((mutations) => {
|
50 |
+
scrollToBottom();
|
51 |
+
});
|
52 |
+
|
53 |
+
// Start observing the document body for changes
|
54 |
+
const streamlitDoc = window.parent.document;
|
55 |
+
observer.observe(streamlitDoc.body, {
|
56 |
+
childList: true,
|
57 |
+
subtree: true
|
58 |
+
});
|
59 |
+
|
60 |
+
// Initial scroll and disconnect after some time
|
61 |
+
scrollToBottom();
|
62 |
+
setTimeout(() => {
|
63 |
+
observer.disconnect();
|
64 |
+
// One final scroll
|
65 |
+
scrollToBottom();
|
66 |
+
}, 1000);
|
67 |
+
</script>
|
68 |
+
"""
|
69 |
+
|
70 |
+
# Use unsafe_allow_html to inject JavaScript
|
71 |
+
st.markdown(js_code, unsafe_allow_html=True)
|
72 |
+
|
73 |
+
|
74 |
# At the start of main function or execution flow
|
75 |
add_sticky_header_css()
|
76 |
|