georad commited on
Commit
60601c1
·
verified ·
1 Parent(s): 0682b30

Update pages/home.py

Browse files
Files changed (1) hide show
  1. pages/home.py +33 -68
pages/home.py CHANGED
@@ -3,58 +3,6 @@ import streamlit.components.v1 as components
3
  from streamlit_shortcuts import button, add_keyboard_shortcuts
4
  import base64
5
 
6
- # This is the key secret to making auto-scrolling work
7
- # By registering query parameters, we can control which part of the page to show
8
- import time
9
- from urllib.parse import quote
10
-
11
- st.header("Tags the below 5 medical entities")
12
- st.write("ACTIVITY")
13
- st.write("ADMINISTRATION")
14
- st.write("AGE")
15
- st.write("AREA")
16
- st.write("BIOLOGICAL_ATTRIBUTE")
17
-
18
- # Initialize session state to track if we need to scroll
19
- if 'init_scroll' not in st.session_state:
20
- st.session_state.init_scroll = True
21
-
22
- # Show all the content
23
- st.subheader("Scrollable Content")
24
- for i in range(99): # Show all but the last item
25
- st.write(f"This is scrollable content line {i}")
26
-
27
- # Bottom indicator and the last line (this is what we'll scroll to)
28
- bottom_content = st.container()
29
- with bottom_content:
30
- st.write("This is scrollable content line 99")
31
- st.success("🔽 Bottom of the page 🔽")
32
-
33
- # Create a button that will refresh the page, causing the auto-scroll code to execute
34
- if st.button("Click to Scroll to Bottom") or st.session_state.init_scroll:
35
- # Update session state so it only auto-scrolls once unless button is clicked
36
- st.session_state.init_scroll = False
37
-
38
- # This is the trick: inject a small snippet that forces the container
39
- # to be navigated to via HTML anchor
40
- bottom_anchor_id = f"bottom-{int(time.time())}"
41
- st.markdown(f"<div id='{bottom_anchor_id}'></div>", unsafe_allow_html=True)
42
-
43
- # Force a page rerun with a focus on the bottom section
44
- # This query parameter approach sometimes works where JavaScript fails
45
- js = f"""
46
- <script>
47
- // Try to scroll to the bottom using multiple methods
48
- document.getElementById('{bottom_anchor_id}').scrollIntoView();
49
- window.location.href = "#bottom-{bottom_anchor_id}";
50
-
51
- // As a fallback, try a direct scroll command
52
- window.scrollTo(0, document.body.scrollHeight);
53
- </script>
54
- """
55
- st.components.v1.html(js, height=0)
56
-
57
- '''
58
  st.title("📘Named Entity Recognition")
59
 
60
  st.header("Tags the below 41 medical entities")
@@ -100,21 +48,38 @@ st.header("Tags the below 41 medical entities")
100
  'VOLUME'
101
  'WEIGHT'
102
 
103
- # Create scrollable content
104
- for i in range(100):
105
- st.write(f"This is scrollable content line {i}")
106
 
107
- # Create an anchor at the bottom
108
- st.markdown('<div id="bottom"></div>', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
- # Add JavaScript to automatically scroll to the anchor
111
- st.markdown("""
112
- <script>
113
- // Set a timeout to ensure the page has loaded
114
- setTimeout(function() {
115
- // Scroll to the bottom anchor
116
- document.getElementById('bottom').scrollIntoView();
117
- }, 500);
118
- </script>
119
- """, unsafe_allow_html=True)
120
- '''
 
3
  from streamlit_shortcuts import button, add_keyboard_shortcuts
4
  import base64
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  st.title("📘Named Entity Recognition")
7
 
8
  st.header("Tags the below 41 medical entities")
 
48
  'VOLUME'
49
  'WEIGHT'
50
 
 
 
 
51
 
52
+ # Generate the content
53
+ content_lines = [f"This is scrollable content line {i}" for i in range(100)]
54
+ content_html = "<br>".join(content_lines)
55
+
56
+ # Create HTML with auto-scroll functionality
57
+ html_content = f"""
58
+ <!DOCTYPE html>
59
+ <html>
60
+ <head>
61
+ <style>
62
+ body {{
63
+ font-family: sans-serif;
64
+ padding: 10px;
65
+ }}
66
+ </style>
67
+ </head>
68
+ <body>
69
+ {content_html}
70
+ <script>
71
+ // Auto-scroll to bottom when loaded
72
+ window.onload = function() {{
73
+ window.scrollTo(0, document.body.scrollHeight);
74
+ }};
75
+ </script>
76
+ </body>
77
+ </html>
78
+ """
79
+
80
+ # Display the content in an iframe (this isolates the JavaScript execution)
81
+ st.components.v1.html(html_content, height=400, scrolling=True)
82
 
83
+ # Add a button that refreshes the page (useful if the auto-scroll doesn't work)
84
+ if st.button("Scroll to Bottom"):
85
+ pass # This will cause the page to refresh