Update app.py
Browse files
app.py
CHANGED
@@ -1,71 +1,62 @@
|
|
1 |
import streamlit as st
|
2 |
|
3 |
# Set page config
|
4 |
-
st.set_page_config(page_title="
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
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 |
-
|
40 |
-
|
41 |
-
// Backup in case the first attempt fails
|
42 |
-
setTimeout(createStickyHeader, 1000);
|
43 |
-
</script>
|
44 |
-
"""
|
45 |
|
46 |
-
#
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
-
#
|
50 |
-
|
51 |
|
52 |
-
#
|
53 |
-
st.
|
54 |
-
|
55 |
-
st.
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
-
|
61 |
-
st.
|
62 |
-
|
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 ---
|