georad commited on
Commit
504d34e
·
verified ·
1 Parent(s): 607614b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +132 -95
app.py CHANGED
@@ -1,120 +1,157 @@
1
  import streamlit as st
2
 
3
-
4
  import time
5
 
6
  # Set page config
7
- st.set_page_config(page_title="Reliable Sticky Status", layout="wide")
8
-
9
- # Create an empty container at the top that will serve as our sticky status container
10
- sticky_container = st.empty()
11
-
12
- # Use JavaScript to track the real status widget and mirror its state to our custom container
13
- js_code = """
14
- <script>
15
- // Function to observe changes in the status widget
16
- function observeStatusWidget() {
17
- // Try to find the actual status widget
18
- const statusWidget = document.querySelector('[data-testid="stStatusWidget"]');
19
- const runningIndicator = document.querySelector('.stStatusWidget span:contains("Running")');
20
- const stopButton = document.querySelector('button[kind="formSubmit"]');
21
 
22
- // Update our custom status mirror
23
- const customStatus = document.getElementById('custom-status-mirror');
24
- if (customStatus) {
25
- if (runningIndicator) {
26
- customStatus.className = 'status-running';
27
- customStatus.textContent = 'RUNNING';
28
- } else {
29
- customStatus.className = 'status-idle';
30
- customStatus.textContent = 'IDLE';
31
- }
32
- }
33
 
34
- // Continue checking
35
- setTimeout(observeStatusWidget, 500);
36
- }
37
-
38
- // Start observing after a delay to ensure DOM is loaded
39
- setTimeout(observeStatusWidget, 1000);
40
- </script>
41
 
 
 
42
  <style>
43
- /* Position the sticky container */
44
- #sticky-status-container {
45
  position: fixed;
46
- top: 0;
47
- left: 0;
48
- right: 0;
49
- background-color: white;
50
- padding: 10px;
51
- z-index: 9999;
52
- border-bottom: 1px solid #ddd;
53
- box-shadow: 0 2px 5px rgba(0,0,0,0.1);
 
 
54
  display: flex;
55
- justify-content: space-between;
56
  align-items: center;
57
- }
58
-
59
- /* Style the status indicators */
60
- #custom-status-mirror {
61
- padding: 5px 10px;
62
- border-radius: 4px;
63
  font-weight: bold;
64
  }
65
 
66
- .status-running {
67
- background-color: #ffeb3b;
68
- color: #000;
69
  }
70
 
71
- .status-idle {
72
- background-color: #4caf50;
73
- color: white;
 
 
 
 
 
 
 
 
 
 
 
 
74
  }
75
 
76
- /* Add padding to prevent content from being hidden */
77
- body {
78
- padding-top: 60px;
79
  }
80
  </style>
 
 
 
 
 
81
 
82
- <div id="sticky-status-container">
83
- <h3>My Application</h3>
84
- <div class="status-container">
85
- <span id="custom-status-mirror" class="status-idle">IDLE</span>
86
- </div>
87
- </div>
88
- """
89
-
90
- # Add our JavaScript and custom sticky header
91
- st.components.v1.html(js_code, height=50)
92
-
93
- # Create a function to simulate a long-running process
94
- def run_long_process():
95
- progress_bar = st.progress(0)
96
- for i in range(100):
97
- time.sleep(0.05) # Simulate work being done
98
- progress_bar.progress(i + 1)
99
- st.success("Process completed!")
100
-
101
- # Add a spacer to prevent content overlap with our sticky header
102
- st.markdown("<div style='height: 20px'></div>", unsafe_allow_html=True)
103
-
104
- # Main content of the application
105
- st.title("Application with Status Mirror")
106
- st.write("This app demonstrates a custom sticky status indicator")
107
-
108
- # Add a button to trigger a process
109
- if st.button("Run Process"):
110
- run_long_process()
111
-
112
- # Add content to demonstrate scrolling
113
- st.markdown("## Sample Content")
114
- for i in range(30):
115
- st.write(f"Content line {i}")
116
- if i % 10 == 0:
117
- st.markdown(f"### Section {i//10 + 1}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  # --- SHARED ON ALL PAGES ---
120
  st.logo(image="images/menu_book_60dp_75FBFD.png")
 
1
  import streamlit as st
2
 
 
3
  import time
4
 
5
  # Set page config
6
+ st.set_page_config(page_title="Floating Status Button", layout="wide")
7
+
8
+ # Initialize session state variables for tracking status
9
+ if 'processing' not in st.session_state:
10
+ st.session_state.processing = False
11
+ if 'section' not in st.session_state:
12
+ st.session_state.section = 'top'
13
+
14
+ # Functions to update state
15
+ def start_processing():
16
+ st.session_state.processing = True
 
 
 
17
 
18
+ def end_processing():
19
+ st.session_state.processing = False
 
 
 
 
 
 
 
 
 
20
 
21
+ def go_to_section(section):
22
+ st.session_state.section = section
 
 
 
 
 
23
 
24
+ # Add CSS for floating button
25
+ st.markdown("""
26
  <style>
27
+ /* Floating action button style */
28
+ .float-button {
29
  position: fixed;
30
+ width: 60px;
31
+ height: 60px;
32
+ bottom: 40px;
33
+ right: 40px;
34
+ background-color: #0066ff;
35
+ color: #FFF;
36
+ border-radius: 50px;
37
+ text-align: center;
38
+ box-shadow: 2px 2px 3px #999;
39
+ z-index: 99999;
40
  display: flex;
41
+ justify-content: center;
42
  align-items: center;
43
+ font-size: 16px;
44
+ text-decoration: none;
 
 
 
 
45
  font-weight: bold;
46
  }
47
 
48
+ .float-button.processing {
49
+ background-color: #ff9800;
50
+ animation: pulse 1.5s infinite;
51
  }
52
 
53
+ @keyframes pulse {
54
+ 0% {
55
+ transform: scale(0.95);
56
+ box-shadow: 0 0 0 0 rgba(255, 152, 0, 0.7);
57
+ }
58
+
59
+ 70% {
60
+ transform: scale(1);
61
+ box-shadow: 0 0 0 10px rgba(255, 152, 0, 0);
62
+ }
63
+
64
+ 100% {
65
+ transform: scale(0.95);
66
+ box-shadow: 0 0 0 0 rgba(255, 152, 0, 0);
67
+ }
68
  }
69
 
70
+ /* Hide the default scrollbar */
71
+ ::-webkit-scrollbar {
72
+ display: none;
73
  }
74
  </style>
75
+ """, unsafe_allow_html=True)
76
+
77
+ # Create a floating button that shows status and allows navigating to top
78
+ button_class = "float-button processing" if st.session_state.processing else "float-button"
79
+ button_text = "⌛" if st.session_state.processing else "⬆️"
80
 
81
+ # Use a dummy button to navigate
82
+ st.markdown(f"""
83
+ <a href="#top" class="{button_class}" id="status-float-button">{button_text}</a>
84
+ """, unsafe_allow_html=True)
85
+
86
+ # Main content with sections and navigation
87
+ st.title("App with Floating Status", anchor="top")
88
+ st.write("This app demonstrates a floating status button that also lets you navigate back to top")
89
+
90
+ # Create navigation tabs
91
+ tabs = st.tabs(["Section 1", "Section 2", "Section 3"])
92
+
93
+ with tabs[0]:
94
+ st.header("Section 1")
95
+ st.write("Content for section 1")
96
+
97
+ # Add a button that triggers processing
98
+ if st.button("Start Process 1", on_click=start_processing):
99
+ with st.spinner("Running process..."):
100
+ # Simulate work
101
+ progress = st.progress(0)
102
+ for i in range(100):
103
+ time.sleep(0.02)
104
+ progress.progress(i + 1)
105
+ end_processing()
106
+ st.success("Process 1 completed!")
107
+
108
+ # Add content for scrolling
109
+ for i in range(10):
110
+ st.write(f"Content line {i} in section 1")
111
+
112
+ with tabs[1]:
113
+ st.header("Section 2")
114
+ st.write("Content for section 2")
115
+
116
+ # Add a button that triggers processing
117
+ if st.button("Start Process 2", on_click=start_processing):
118
+ with st.spinner("Running process..."):
119
+ # Simulate more complex work
120
+ progress = st.progress(0)
121
+ for i in range(100):
122
+ time.sleep(0.03)
123
+ progress.progress(i + 1)
124
+ end_processing()
125
+ st.success("Process 2 completed!")
126
+
127
+ # Add content for scrolling
128
+ for i in range(10):
129
+ st.write(f"Content line {i} in section 2")
130
+
131
+ with tabs[2]:
132
+ st.header("Section 3")
133
+ st.write("Content for section 3")
134
+
135
+ # Add a button that triggers processing
136
+ if st.button("Start Process 3", on_click=start_processing):
137
+ with st.spinner("Running process..."):
138
+ # Simulate complex work
139
+ progress = st.progress(0)
140
+ for i in range(100):
141
+ time.sleep(0.04)
142
+ progress.progress(i + 1)
143
+ end_processing()
144
+ st.success("Process 3 completed!")
145
+
146
+ # Add content for scrolling
147
+ for i in range(10):
148
+ st.write(f"Content line {i} in section 3")
149
+
150
+ # Add more content to ensure sufficient scrolling
151
+ st.markdown("---")
152
+ st.header("Additional Content")
153
+ for i in range(20):
154
+ st.write(f"Additional content line {i}")
155
 
156
  # --- SHARED ON ALL PAGES ---
157
  st.logo(image="images/menu_book_60dp_75FBFD.png")