File size: 5,554 Bytes
d8f56b1 53dcb25 ac35dad bee7cf0 ac35dad ce47786 ac35dad ce47786 ac35dad ce47786 ac35dad ce47786 bee7cf0 ac35dad bee7cf0 ac35dad ce47786 bee7cf0 ac35dad bee7cf0 ac35dad 561774a 57dfc0c 9176e69 9f0fc30 057e688 b50938f 9038e9e b47a09c 9038e9e 057e688 957d115 057e688 fe5cb7d |
1 2 3 4 5 6 7 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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
import streamlit as st
import time
from datetime import datetime
# Set page config
st.set_page_config(page_title="Custom Status Indicator", layout="wide")
# Initialize session state for our custom status indicator
if 'last_update' not in st.session_state:
st.session_state.last_update = datetime.now().strftime("%H:%M:%S")
if 'is_running' not in st.session_state:
st.session_state.is_running = False
# Function to toggle the running state
def toggle_running_state():
st.session_state.is_running = not st.session_state.is_running
st.session_state.last_update = datetime.now().strftime("%H:%M:%S")
# Function to simulate a computation/process
def run_process():
with st.spinner("Running process..."):
# Simulate work
time.sleep(3)
st.success("Process completed!")
st.session_state.is_running = False
st.session_state.last_update = datetime.now().strftime("%H:%M:%S")
# Create a container for our fixed header
header = st.container()
# Add CSS to fix our custom status indicator at the top
st.markdown("""
<style>
/* Fix the first container to serve as our header */
.stApp > div:first-child {
position: sticky !important;
top: 0 !important;
background-color: white !important;
z-index: 999 !important;
padding: 1rem !important;
border-bottom: 1px solid #f0f0f0 !important;
box-shadow: 0 2px 5px rgba(0,0,0,0.1) !important;
}
/* Custom status indicator styles */
.status-indicator {
display: inline-block;
padding: 5px 10px;
border-radius: 4px;
margin-right: 10px;
}
.status-running {
background-color: #ffeb3b;
color: #000;
}
.status-idle {
background-color: #4caf50;
color: white;
}
</style>
""", unsafe_allow_html=True)
# Create our custom status indicator in the header container
with header:
cols = st.columns([3, 1])
with cols[0]:
st.title("App with Custom Status Indicator")
with cols[1]:
status_class = "status-running" if st.session_state.is_running else "status-idle"
status_text = "RUNNING" if st.session_state.is_running else "IDLE"
st.markdown(f"""
<div style="display: flex; align-items: center; justify-content: flex-end;">
<div class="status-indicator {status_class}">{status_text}</div>
<div>Last update: {st.session_state.last_update}</div>
</div>
""", unsafe_allow_html=True)
if st.button("Run Process" if not st.session_state.is_running else "Stop",
key="run_button",
on_click=toggle_running_state):
# If we're now in running state, execute the process
if st.session_state.is_running:
run_process()
# Main content area
st.write("Scroll down to test if the custom status indicator stays visible")
# Add a separator
st.markdown("---")
# Create some tabs to organize content
tab1, tab2, tab3 = st.tabs(["Tab 1", "Tab 2", "Tab 3"])
with tab1:
st.header("Tab 1 Content")
st.write("This is the content of tab 1")
# Add some sample content for scrolling
for i in range(10):
st.write(f"Content line {i} in tab 1")
if st.button("Run Process in Tab 1"):
with st.spinner("Running process in Tab 1..."):
st.session_state.is_running = True
time.sleep(2)
st.session_state.is_running = False
st.session_state.last_update = datetime.now().strftime("%H:%M:%S")
st.success("Process completed in Tab 1!")
with tab2:
st.header("Tab 2 Content")
st.write("This is the content of tab 2")
# Add some sample content for scrolling
for i in range(10):
st.write(f"Content line {i} in tab 2")
if st.button("Run Process in Tab 2"):
with st.spinner("Running process in Tab 2..."):
st.session_state.is_running = True
time.sleep(3)
st.session_state.is_running = False
st.session_state.last_update = datetime.now().strftime("%H:%M:%S")
st.success("Process completed in Tab 2!")
with tab3:
st.header("Tab 3 Content")
st.write("This is the content of tab 3")
# Add some sample content for scrolling
for i in range(10):
st.write(f"Content line {i} in tab 3")
if st.button("Run Process in Tab 3"):
with st.spinner("Running process in Tab 3..."):
st.session_state.is_running = True
time.sleep(4)
st.session_state.is_running = False
st.session_state.last_update = datetime.now().strftime("%H:%M:%S")
st.success("Process completed in Tab 3!")
# Add more content to ensure we have enough to scroll
st.markdown("---")
st.header("Additional Content")
for i in range(10):
st.write(f"Additional content line {i}")
# --- SHARED ON ALL PAGES ---
st.logo(image="images/menu_book_60dp_75FBFD.png")
st.sidebar.title("SBS V2.0 mapper")
st.sidebar.subheader("(work in progress)")
st.sidebar.text("Demo by JA-RAD")
# --- PAGE SETUP ---
type_text_page = st.Page(
page="pages/type_text.py",
title="DEMO (work in progress)",
icon=":material/keyboard:",
default=True,)
# --- NAVIGATION SETUP ---
pg = st.navigation(pages=[type_text_page]) # WITHOUT SECTIONS
#pg = st.navigation({"Chapter_Index": [start_page], "Demo": [type_text_page, upload_file_page], "About": [about_page]}) # WITH SECTIONS
pg.run() |