georad commited on
Commit
45d1ec2
·
verified ·
1 Parent(s): 8cd1dac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -32
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import streamlit as st
 
2
 
3
  # At the top of file with imports
4
  def add_sticky_header_css():
@@ -29,47 +30,39 @@ def add_sticky_header_css():
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()
 
1
  import streamlit as st
2
+ import base64
3
 
4
  # At the top of file with imports
5
  def add_sticky_header_css():
 
30
  </style>
31
  """, unsafe_allow_html=True)
32
 
33
+ def auto_scroll_to_bottom():
34
+ # JavaScript to scroll to bottom
35
  js_code = """
36
  <script>
37
+ // Wait for the page to fully render
38
+ const scrollToBottom = () => {
39
+ // Get the main Streamlit iframe
40
+ const streamlitDoc = window.parent.document;
41
+ // Get the app container
42
+ const appContainer = streamlitDoc.querySelector('.main');
43
+ if (appContainer) {
44
+ // Scroll the app container to the bottom
45
+ appContainer.scrollTop = appContainer.scrollHeight;
46
+ } else {
47
+ // Fallback to scrolling the entire page
48
+ window.parent.scrollTo(0, streamlitDoc.body.scrollHeight);
49
  }
50
+ };
51
 
52
+ // Try immediately
53
+ scrollToBottom();
 
 
54
 
55
+ // Also try after a short delay to ensure content is rendered
56
+ setTimeout(scrollToBottom, 200);
 
 
 
 
57
 
58
+ // And after a longer delay just to be safe
59
+ setTimeout(scrollToBottom, 500);
 
 
 
 
 
60
  </script>
61
  """
62
 
63
+ # Render the JavaScript code
64
+ html = f'<div style="display:none">{js_code}</div>'
65
+ st.components.v1.html(html, height=0)
66
 
67
  # At the start of main function or execution flow
68
  add_sticky_header_css()