Update app.py
Browse files
app.py
CHANGED
@@ -1,46 +1,153 @@
|
|
1 |
import streamlit as st
|
2 |
|
|
|
|
|
|
|
3 |
# Set page config
|
4 |
-
st.set_page_config(page_title="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
st.markdown("""
|
8 |
<style>
|
9 |
-
/*
|
10 |
-
|
11 |
-
|
12 |
-
.stApp > header {
|
13 |
-
position: fixed !important;
|
14 |
top: 0 !important;
|
15 |
-
left: 0 !important;
|
16 |
-
right: 0 !important;
|
17 |
-
height: auto !important;
|
18 |
-
z-index: 999999 !important;
|
19 |
background-color: white !important;
|
20 |
-
|
|
|
|
|
|
|
21 |
}
|
22 |
|
23 |
-
/*
|
24 |
-
.
|
25 |
-
|
|
|
|
|
|
|
26 |
}
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
}
|
32 |
</style>
|
33 |
""", unsafe_allow_html=True)
|
34 |
|
35 |
-
#
|
36 |
-
|
37 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
#
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
|
45 |
# --- SHARED ON ALL PAGES ---
|
46 |
st.logo(image="images/menu_book_60dp_75FBFD.png")
|
|
|
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="Custom Status Indicator", layout="wide")
|
8 |
+
|
9 |
+
# Initialize session state for our custom status indicator
|
10 |
+
if 'last_update' not in st.session_state:
|
11 |
+
st.session_state.last_update = datetime.now().strftime("%H:%M:%S")
|
12 |
+
if 'is_running' not in st.session_state:
|
13 |
+
st.session_state.is_running = False
|
14 |
+
|
15 |
+
# Function to toggle the running state
|
16 |
+
def toggle_running_state():
|
17 |
+
st.session_state.is_running = not st.session_state.is_running
|
18 |
+
st.session_state.last_update = datetime.now().strftime("%H:%M:%S")
|
19 |
|
20 |
+
# Function to simulate a computation/process
|
21 |
+
def run_process():
|
22 |
+
with st.spinner("Running process..."):
|
23 |
+
# Simulate work
|
24 |
+
time.sleep(3)
|
25 |
+
st.success("Process completed!")
|
26 |
+
st.session_state.is_running = False
|
27 |
+
st.session_state.last_update = datetime.now().strftime("%H:%M:%S")
|
28 |
+
|
29 |
+
# Create a container for our fixed header
|
30 |
+
header = st.container()
|
31 |
+
|
32 |
+
# Add CSS to fix our custom status indicator at the top
|
33 |
st.markdown("""
|
34 |
<style>
|
35 |
+
/* Fix the first container to serve as our header */
|
36 |
+
.stApp > div:first-child {
|
37 |
+
position: sticky !important;
|
|
|
|
|
38 |
top: 0 !important;
|
|
|
|
|
|
|
|
|
39 |
background-color: white !important;
|
40 |
+
z-index: 999 !important;
|
41 |
+
padding: 1rem !important;
|
42 |
+
border-bottom: 1px solid #f0f0f0 !important;
|
43 |
+
box-shadow: 0 2px 5px rgba(0,0,0,0.1) !important;
|
44 |
}
|
45 |
|
46 |
+
/* Custom status indicator styles */
|
47 |
+
.status-indicator {
|
48 |
+
display: inline-block;
|
49 |
+
padding: 5px 10px;
|
50 |
+
border-radius: 4px;
|
51 |
+
margin-right: 10px;
|
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 |
+
# Create our custom status indicator in the header container
|
65 |
+
with header:
|
66 |
+
cols = st.columns([3, 1])
|
67 |
+
|
68 |
+
with cols[0]:
|
69 |
+
st.title("App with Custom Status Indicator")
|
70 |
+
|
71 |
+
with cols[1]:
|
72 |
+
status_class = "status-running" if st.session_state.is_running else "status-idle"
|
73 |
+
status_text = "RUNNING" if st.session_state.is_running else "IDLE"
|
74 |
+
|
75 |
+
st.markdown(f"""
|
76 |
+
<div style="display: flex; align-items: center; justify-content: flex-end;">
|
77 |
+
<div class="status-indicator {status_class}">{status_text}</div>
|
78 |
+
<div>Last update: {st.session_state.last_update}</div>
|
79 |
+
</div>
|
80 |
+
""", unsafe_allow_html=True)
|
81 |
+
|
82 |
+
if st.button("Run Process" if not st.session_state.is_running else "Stop",
|
83 |
+
key="run_button",
|
84 |
+
on_click=toggle_running_state):
|
85 |
+
# If we're now in running state, execute the process
|
86 |
+
if st.session_state.is_running:
|
87 |
+
run_process()
|
88 |
+
|
89 |
+
# Main content area
|
90 |
+
st.write("Scroll down to test if the custom status indicator stays visible")
|
91 |
+
|
92 |
+
# Add a separator
|
93 |
+
st.markdown("---")
|
94 |
+
|
95 |
+
# Create some tabs to organize content
|
96 |
+
tab1, tab2, tab3 = st.tabs(["Tab 1", "Tab 2", "Tab 3"])
|
97 |
+
|
98 |
+
with tab1:
|
99 |
+
st.header("Tab 1 Content")
|
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")
|