georad commited on
Commit
8e54ba1
·
verified ·
1 Parent(s): 26483c9

Update pages/type_text.py

Browse files
Files changed (1) hide show
  1. pages/type_text.py +95 -0
pages/type_text.py CHANGED
@@ -9,6 +9,101 @@ import time
9
  import os
10
  os.getenv("HF_TOKEN")
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  #hide_streamlit_style = """
14
  # <style>
 
9
  import os
10
  os.getenv("HF_TOKEN")
11
 
12
+ import streamlit as st
13
+
14
+ # 0. If stStatusWidget is a custom component, make sure it's defined or imported.
15
+ # For demonstration, let's create a placeholder function for stStatusWidget.
16
+ # Replace this with your actual stStatusWidget or the widgets you want to use.
17
+ def stStatusWidget():
18
+ col1, col2, col3 = st.columns(3)
19
+ with col1:
20
+ st.metric("Temperature", "25 °C", "1.2 °C")
21
+ with col2:
22
+ st.metric("Humidity", "60%", "-5%")
23
+ with col3:
24
+ st.info("System Status: OK")
25
+
26
+ # 1. Define the CSS for the sticky header
27
+ # Note: The background color is important so content doesn't show through.
28
+ # You might want to adjust it to match your Streamlit theme.
29
+ # Streamlit's default light theme background is #f0f2f6 or white.
30
+ # Streamlit's default dark theme background is #0e1117.
31
+ # Using a generic white/light gray is often a safe bet.
32
+ sticky_header_css = """
33
+ <style>
34
+ div[data-testid="stVerticalBlock"] div:has(div.sticky-header) {
35
+ position: sticky;
36
+ top: 2.875rem; /* Adjust this value if you have a page icon or title taking up space */
37
+ background-color: white;
38
+ z-index: 999;
39
+ box-shadow: 0 2px 4px 0 rgba(0,0,0,0.1); /* Optional: for a slight shadow */
40
+ padding-bottom: 0.5rem; /* Optional: for some spacing */
41
+ }
42
+
43
+ .sticky-header {
44
+ /* You can add additional styling for the header itself if needed */
45
+ /* border-bottom: 1px solid #e6e6e6; */ /* Optional: a bottom border */
46
+ }
47
+
48
+ /* Nudge the actual page content down a bit if the sticky header is tall */
49
+ /* This is optional and depends on your header's height and content */
50
+ /*
51
+ div[data-testid="stAppViewContainer"] > section:first-of-type {
52
+ padding-top: 5rem; /* Adjust this based on your header's height */
53
+ }
54
+ */
55
+
56
+ /*
57
+ Alternative for top positioning if you want it absolutely at the top,
58
+ but this might conflict with Streamlit's own header bar if you're using st.set_page_config with a title/icon.
59
+ If you're not, or want to cover it, top: 0; might be better.
60
+ */
61
+ /*
62
+ div[data-testid="stVerticalBlock"] div:has(div.sticky-header) {
63
+ position: sticky;
64
+ top: 0; // Use this if you have no page title/icon in Streamlit's native header bar
65
+ background-color: white;
66
+ z-index: 999;
67
+ }
68
+ */
69
+ </style>
70
+ """
71
+ st.markdown(sticky_header_css, unsafe_allow_html=True)
72
+
73
+ # 2. Create the header content within a div that has the 'sticky-header' class.
74
+ # We use st.markdown to open the div, then Streamlit widgets, then st.markdown to close.
75
+
76
+ st.markdown('<div class="sticky-header">', unsafe_allow_html=True)
77
+
78
+ # --- Your Header Content ---
79
+ # st.title("My Application Dashboard") # You can have a title
80
+ # st.markdown("---") # Optional separator
81
+
82
+ # Example using columns for layout
83
+ header_cols = st.columns([3, 2]) # Adjust ratios as needed
84
+ with header_cols[0]:
85
+ st.subheader("Dashboard Overview 📊")
86
+ # You could put a logo here: st.image("logo.png", width=100)
87
+ with header_cols[1]:
88
+ # Call your stStatusWidget or place its constituent widgets here
89
+ stStatusWidget() # Our placeholder status widget
90
+
91
+ st.markdown('</div>', unsafe_allow_html=True)
92
+
93
+ # 3. Add the rest of your page content to demonstrate scrolling
94
+ st.markdown("## Main Content Area")
95
+ st.write("Scroll down to see the header stick.")
96
+
97
+ for i in range(50):
98
+ st.write(f"Dummy content line {i+1} to make the page scrollable.")
99
+ if (i+1) % 10 == 0:
100
+ st.image("https://streamlit.io/images/brand/streamlit-logo-secondary-colormark-darktext.png", width=300)
101
+
102
+ st.markdown("---")
103
+ st.write("End of content.")
104
+
105
+
106
+
107
 
108
  #hide_streamlit_style = """
109
  # <style>