File size: 3,922 Bytes
d8f56b1
53dcb25
607614b
ac35dad
 
bee7cf0
607614b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce47786
607614b
 
 
 
 
 
 
 
 
 
 
 
 
 
ce47786
bee7cf0
607614b
 
ac35dad
 
607614b
bee7cf0
607614b
ac35dad
 
 
 
607614b
ac35dad
 
 
ce47786
607614b
 
 
 
 
ce47786
bee7cf0
607614b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st 


import time

# Set page config
st.set_page_config(page_title="Reliable Sticky Status", layout="wide")

# Create an empty container at the top that will serve as our sticky status container
sticky_container = st.empty()

# Use JavaScript to track the real status widget and mirror its state to our custom container
js_code = """
<script>
// Function to observe changes in the status widget
function observeStatusWidget() {
    // Try to find the actual status widget
    const statusWidget = document.querySelector('[data-testid="stStatusWidget"]');
    const runningIndicator = document.querySelector('.stStatusWidget span:contains("Running")');
    const stopButton = document.querySelector('button[kind="formSubmit"]');
    
    // Update our custom status mirror
    const customStatus = document.getElementById('custom-status-mirror');
    if (customStatus) {
        if (runningIndicator) {
            customStatus.className = 'status-running';
            customStatus.textContent = 'RUNNING';
        } else {
            customStatus.className = 'status-idle';
            customStatus.textContent = 'IDLE';
        }
    }
    
    // Continue checking
    setTimeout(observeStatusWidget, 500);
}

// Start observing after a delay to ensure DOM is loaded
setTimeout(observeStatusWidget, 1000);
</script>

<style>
    /* Position the sticky container */
    #sticky-status-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        background-color: white;
        padding: 10px;
        z-index: 9999;
        border-bottom: 1px solid #ddd;
        box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    /* Style the status indicators */
    #custom-status-mirror {
        padding: 5px 10px;
        border-radius: 4px;
        font-weight: bold;
    }
    
    .status-running {
        background-color: #ffeb3b;
        color: #000;
    }
    
    .status-idle {
        background-color: #4caf50;
        color: white;
    }
    
    /* Add padding to prevent content from being hidden */
    body {
        padding-top: 60px;
    }
</style>

<div id="sticky-status-container">
    <h3>My Application</h3>
    <div class="status-container">
        <span id="custom-status-mirror" class="status-idle">IDLE</span>
    </div>
</div>
"""

# Add our JavaScript and custom sticky header
st.components.v1.html(js_code, height=50)

# Create a function to simulate a long-running process
def run_long_process():
    progress_bar = st.progress(0)
    for i in range(100):
        time.sleep(0.05)  # Simulate work being done
        progress_bar.progress(i + 1)
    st.success("Process completed!")

# Add a spacer to prevent content overlap with our sticky header
st.markdown("<div style='height: 20px'></div>", unsafe_allow_html=True)

# Main content of the application
st.title("Application with Status Mirror")
st.write("This app demonstrates a custom sticky status indicator")

# Add a button to trigger a process
if st.button("Run Process"):
    run_long_process()

# Add content to demonstrate scrolling
st.markdown("## Sample Content")
for i in range(30):
    st.write(f"Content line {i}")
    if i % 10 == 0:
        st.markdown(f"### Section {i//10 + 1}")

# --- 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()