georad commited on
Commit
8393070
·
verified ·
1 Parent(s): cbb5f8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -58
app.py CHANGED
@@ -1,71 +1,62 @@
1
  import streamlit as st
2
 
3
  # Set page config
4
- st.set_page_config(page_title="Experimental Solution", layout="wide")
5
 
6
- # Use JavaScript to create and maintain a sticky header
7
- js_code = """
8
- <script>
9
- // Function to create sticky header
10
- function createStickyHeader() {
11
- // Create header element
12
- const header = document.createElement('div');
13
- header.style.position = 'fixed';
14
- header.style.top = '0';
15
- header.style.left = '0';
16
- header.style.width = '100%';
17
- header.style.backgroundColor = '#262730';
18
- header.style.color = 'white';
19
- header.style.padding = '10px';
20
- header.style.zIndex = '9999';
21
- header.style.textAlign = 'center';
22
- header.style.boxShadow = '0 2px 5px rgba(0,0,0,0.2)';
23
-
24
- // Add content to header
25
- header.innerHTML = `
26
- <h3 style="display:inline-block; margin:0 20px;">My App Navigation</h3>
27
- <a href="#section1" style="color:white; margin:0 10px;">Section 1</a>
28
- <a href="#section2" style="color:white; margin:0 10px;">Section 2</a>
29
- <a href="#section3" style="color:white; margin:0 10px;">Section 3</a>
30
- `;
31
-
32
- // Append header to body
33
- document.body.appendChild(header);
34
-
35
- // Add padding to top of body to prevent content from being hidden
36
- document.body.style.paddingTop = (header.offsetHeight + 10) + 'px';
37
- }
38
 
39
- // Initialize when DOM is loaded
40
- document.addEventListener('DOMContentLoaded', createStickyHeader);
41
- // Backup in case the first attempt fails
42
- setTimeout(createStickyHeader, 1000);
43
- </script>
44
- """
45
 
46
- # Inject the JavaScript
47
- st.components.v1.html(js_code, height=0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
- # Add a small spacer for header
50
- st.markdown("<div style='height:60px;'></div>", unsafe_allow_html=True)
51
 
52
- # Regular Streamlit content
53
- st.title("My Application")
54
-
55
- st.header("Section 1", anchor="section1")
56
- st.write("This is section 1 content")
57
- for i in range(10):
58
- st.write(f"Content line {i}")
 
 
 
 
 
 
 
 
 
 
 
59
 
60
- st.header("Section 2", anchor="section2")
61
- st.write("This is section 2 content")
62
- for i in range(10):
63
- st.write(f"Content line {i}")
64
 
65
- st.header("Section 3", anchor="section3")
66
- st.write("This is section 3 content")
67
- for i in range(10):
68
- st.write(f"Content line {i}")
69
 
70
 
71
  # --- SHARED ON ALL PAGES ---
 
1
  import streamlit as st
2
 
3
  # Set page config
4
+ st.set_page_config(page_title="Virtual Sticky Header", layout="wide")
5
 
6
+ # Create a session state to track which section we're viewing
7
+ if 'current_section' not in st.session_state:
8
+ st.session_state.current_section = "section1"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ # Create columns for our layout
11
+ col1, col2, col3 = st.columns([1, 2, 1])
 
 
 
 
12
 
13
+ # Function to create our "sticky" header
14
+ def create_header():
15
+ with st.container():
16
+ st.markdown("### My Application")
17
+ tab1, tab2, tab3 = st.tabs(["Section 1", "Section 2", "Section 3"])
18
+
19
+ with tab1:
20
+ if st.button("Go to Section 1"):
21
+ st.session_state.current_section = "section1"
22
+ st.experimental_rerun()
23
+
24
+ with tab2:
25
+ if st.button("Go to Section 2"):
26
+ st.session_state.current_section = "section2"
27
+ st.experimental_rerun()
28
+
29
+ with tab3:
30
+ if st.button("Go to Section 3"):
31
+ st.session_state.current_section = "section3"
32
+ st.experimental_rerun()
33
 
34
+ # Create our header
35
+ create_header()
36
 
37
+ # Display content based on the current section
38
+ if st.session_state.current_section == "section1":
39
+ st.header("Section 1")
40
+ st.write("This is section 1 content")
41
+ for i in range(10):
42
+ st.write(f"Content line {i}")
43
+
44
+ elif st.session_state.current_section == "section2":
45
+ st.header("Section 2")
46
+ st.write("This is section 2 content")
47
+ for i in range(10):
48
+ st.write(f"Content line {i}")
49
+
50
+ elif st.session_state.current_section == "section3":
51
+ st.header("Section 3")
52
+ st.write("This is section 3 content")
53
+ for i in range(10):
54
+ st.write(f"Content line {i}")
55
 
56
+ # Add a "back to top" button at the bottom
57
+ if st.button("Back to Top"):
58
+ st.experimental_rerun()
 
59
 
 
 
 
 
60
 
61
 
62
  # --- SHARED ON ALL PAGES ---