georad commited on
Commit
0c6ff07
·
verified ·
1 Parent(s): 4db2c59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -35
app.py CHANGED
@@ -1,60 +1,89 @@
1
  import streamlit as st
2
 
3
  # Set page config
4
- st.set_page_config(page_title="Multipage Navigation", layout="wide")
5
 
6
- # Use sidebar as a persistent navigation element (this is always visible)
7
- with st.sidebar:
8
- st.title("My Application")
9
- st.markdown("### Navigation")
10
-
11
- nav_option = st.radio(
12
- "Go to:",
13
- ["Section 1", "Section 2", "Section 3"],
14
- key="nav_radio"
15
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- # Main content area
 
 
 
 
 
18
  st.title("My Application")
19
 
20
- # Display content based on navigation selection
21
- if nav_option == "Section 1":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  st.header("Section 1")
23
  st.write("This is section 1 content")
24
  for i in range(15):
25
  st.write(f"Content line {i}")
26
 
27
- elif nav_option == "Section 2":
28
  st.header("Section 2")
29
  st.write("This is section 2 content")
30
  for i in range(15):
31
  st.write(f"Content line {i}")
32
 
33
- elif nav_option == "Section 3":
34
  st.header("Section 3")
35
  st.write("This is section 3 content")
36
  for i in range(15):
37
  st.write(f"Content line {i}")
38
 
39
- # Add "quick jump" buttons at the bottom
40
- st.markdown("### Quick Navigation")
41
- col1, col2, col3 = st.columns(3)
42
-
43
- with col1:
44
- if st.button("Jump to Section 1"):
45
- st.session_state.nav_radio = "Section 1"
46
- st.experimental_rerun()
47
-
48
- with col2:
49
- if st.button("Jump to Section 2"):
50
- st.session_state.nav_radio = "Section 2"
51
- st.experimental_rerun()
52
-
53
- with col3:
54
- if st.button("Jump to Section 3"):
55
- st.session_state.nav_radio = "Section 3"
56
- st.experimental_rerun()
57
-
58
 
59
 
60
  # --- SHARED ON ALL PAGES ---
 
1
  import streamlit as st
2
 
3
  # Set page config
4
+ st.set_page_config(page_title="Floating Navigation", layout="wide")
5
 
6
+ # Create a session state for the navigation panel visibility
7
+ if 'show_nav' not in st.session_state:
8
+ st.session_state.show_nav = False
9
+
10
+ # Function to toggle navigation panel
11
+ def toggle_nav():
12
+ st.session_state.show_nav = not st.session_state.show_nav
13
+
14
+ # Add a floating action button style
15
+ st.markdown("""
16
+ <style>
17
+ .floating-button {
18
+ position: fixed;
19
+ bottom: 20px;
20
+ right: 20px;
21
+ background-color: #4CAF50;
22
+ color: white;
23
+ border-radius: 50%;
24
+ width: 60px;
25
+ height: 60px;
26
+ display: flex;
27
+ justify-content: center;
28
+ align-items: center;
29
+ font-size: 24px;
30
+ cursor: pointer;
31
+ z-index: 999;
32
+ box-shadow: 0 4px 8px rgba(0,0,0,0.3);
33
+ }
34
+ </style>
35
+ <div class="floating-button" onclick="document.getElementById('nav-toggle').click();">
36
+
37
+ </div>
38
+ """, unsafe_allow_html=True)
39
 
40
+ # Hidden button to trigger the toggle function
41
+ st.markdown('<button id="nav-toggle" style="display:none"></button>', unsafe_allow_html=True)
42
+ if st.button("Toggle Navigation", key="toggle_button", on_click=toggle_nav):
43
+ pass # This is just to trigger the on_click function
44
+
45
+ # Main content
46
  st.title("My Application")
47
 
48
+ # Conditional navigation panel
49
+ if st.session_state.show_nav:
50
+ with st.container():
51
+ st.markdown("### Quick Navigation")
52
+ if st.button("Go to Section 1"):
53
+ st.session_state.section = "section1"
54
+ st.session_state.show_nav = False
55
+ st.experimental_rerun()
56
+ if st.button("Go to Section 2"):
57
+ st.session_state.section = "section2"
58
+ st.session_state.show_nav = False
59
+ st.experimental_rerun()
60
+ if st.button("Go to Section 3"):
61
+ st.session_state.section = "section3"
62
+ st.session_state.show_nav = False
63
+ st.experimental_rerun()
64
+
65
+ # Content sections
66
+ if 'section' not in st.session_state:
67
+ st.session_state.section = "section1"
68
+
69
+ if st.session_state.section == "section1":
70
  st.header("Section 1")
71
  st.write("This is section 1 content")
72
  for i in range(15):
73
  st.write(f"Content line {i}")
74
 
75
+ elif st.session_state.section == "section2":
76
  st.header("Section 2")
77
  st.write("This is section 2 content")
78
  for i in range(15):
79
  st.write(f"Content line {i}")
80
 
81
+ elif st.session_state.section == "section3":
82
  st.header("Section 3")
83
  st.write("This is section 3 content")
84
  for i in range(15):
85
  st.write(f"Content line {i}")
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
 
89
  # --- SHARED ON ALL PAGES ---