Update app.py
Browse files
app.py
CHANGED
@@ -1,153 +1,120 @@
|
|
1 |
import streamlit as st
|
2 |
|
|
|
3 |
import time
|
4 |
-
from datetime import datetime
|
5 |
|
6 |
# Set page config
|
7 |
-
st.set_page_config(page_title="
|
8 |
-
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
<style>
|
35 |
-
/*
|
36 |
-
|
37 |
-
position:
|
38 |
-
top: 0
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
44 |
}
|
45 |
|
46 |
-
/*
|
47 |
-
|
48 |
-
display: inline-block;
|
49 |
padding: 5px 10px;
|
50 |
border-radius: 4px;
|
51 |
-
|
52 |
}
|
|
|
53 |
.status-running {
|
54 |
background-color: #ffeb3b;
|
55 |
color: #000;
|
56 |
}
|
|
|
57 |
.status-idle {
|
58 |
background-color: #4caf50;
|
59 |
color: white;
|
60 |
}
|
|
|
|
|
|
|
|
|
|
|
61 |
</style>
|
62 |
-
""", unsafe_allow_html=True)
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
st.write("This is the content of tab 1")
|
101 |
-
|
102 |
-
# Add some sample content for scrolling
|
103 |
-
for i in range(10):
|
104 |
-
st.write(f"Content line {i} in tab 1")
|
105 |
-
|
106 |
-
if st.button("Run Process in Tab 1"):
|
107 |
-
with st.spinner("Running process in Tab 1..."):
|
108 |
-
st.session_state.is_running = True
|
109 |
-
time.sleep(2)
|
110 |
-
st.session_state.is_running = False
|
111 |
-
st.session_state.last_update = datetime.now().strftime("%H:%M:%S")
|
112 |
-
st.success("Process completed in Tab 1!")
|
113 |
-
|
114 |
-
with tab2:
|
115 |
-
st.header("Tab 2 Content")
|
116 |
-
st.write("This is the content of tab 2")
|
117 |
-
|
118 |
-
# Add some sample content for scrolling
|
119 |
-
for i in range(10):
|
120 |
-
st.write(f"Content line {i} in tab 2")
|
121 |
-
|
122 |
-
if st.button("Run Process in Tab 2"):
|
123 |
-
with st.spinner("Running process in Tab 2..."):
|
124 |
-
st.session_state.is_running = True
|
125 |
-
time.sleep(3)
|
126 |
-
st.session_state.is_running = False
|
127 |
-
st.session_state.last_update = datetime.now().strftime("%H:%M:%S")
|
128 |
-
st.success("Process completed in Tab 2!")
|
129 |
-
|
130 |
-
with tab3:
|
131 |
-
st.header("Tab 3 Content")
|
132 |
-
st.write("This is the content of tab 3")
|
133 |
-
|
134 |
-
# Add some sample content for scrolling
|
135 |
-
for i in range(10):
|
136 |
-
st.write(f"Content line {i} in tab 3")
|
137 |
-
|
138 |
-
if st.button("Run Process in Tab 3"):
|
139 |
-
with st.spinner("Running process in Tab 3..."):
|
140 |
-
st.session_state.is_running = True
|
141 |
-
time.sleep(4)
|
142 |
-
st.session_state.is_running = False
|
143 |
-
st.session_state.last_update = datetime.now().strftime("%H:%M:%S")
|
144 |
-
st.success("Process completed in Tab 3!")
|
145 |
-
|
146 |
-
# Add more content to ensure we have enough to scroll
|
147 |
-
st.markdown("---")
|
148 |
-
st.header("Additional Content")
|
149 |
-
for i in range(10):
|
150 |
-
st.write(f"Additional content line {i}")
|
151 |
|
152 |
# --- SHARED ON ALL PAGES ---
|
153 |
st.logo(image="images/menu_book_60dp_75FBFD.png")
|
|
|
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")
|