georad commited on
Commit
ec5cbfd
·
verified ·
1 Parent(s): c7ecbd4

Update pages/type_text.py

Browse files
Files changed (1) hide show
  1. pages/type_text.py +76 -0
pages/type_text.py CHANGED
@@ -9,6 +9,82 @@ 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
+ # Determine approximate header height (Streamlit's header is ~54-60px, or 3.375rem to 3.75rem)
13
+ # You might need to inspect element in your browser to get the exact height for your version/theme.
14
+ # Let's use 3.5rem as a common estimate.
15
+ HEADER_HEIGHT_REM = 3.5
16
+ # We also need to account for any default padding Streamlit puts on the main content area.
17
+ # Let's add a little buffer or use a value that ensures content is clearly below.
18
+ # Or, you can be more precise if you know the exact structure.
19
+ MAIN_CONTENT_PADDING_TOP_REM = HEADER_HEIGHT_REM + 1.0 # Header height + 1rem buffer
20
+
21
+ st.markdown(
22
+ f"""
23
+ <style>
24
+ /* Target Streamlit's built-in header */
25
+ header[data-testid="stHeader"] {{
26
+ position: -webkit-sticky; /* For Safari */
27
+ position: sticky;
28
+ top: 0;
29
+ /*
30
+ Streamlit's header already has a z-index (e.g., 1030) and background color.
31
+ If you find it necessary, uncomment and adjust these:
32
+ z-index: 1031 !important;
33
+ background-color: var(--streamlit-header-background-color, var(--secondary-background-color, #f0f2f6));
34
+ */
35
+ }}
36
+
37
+ /* Adjust the main content area's top padding to prevent overlap */
38
+ /* The main content is usually within a <section class="main"> */
39
+ section.main {{
40
+ padding-top: {MAIN_CONTENT_PADDING_TOP_REM}rem !important;
41
+ }}
42
+
43
+ /* You might also need to target a more specific block if the above isn't enough,
44
+ or if Streamlit's structure changes. For example: */
45
+ /*
46
+ .main .block-container {{
47
+ padding-top: {HEADER_HEIGHT_REM}rem !important;
48
+ }}
49
+ */
50
+ </style>
51
+ """,
52
+ unsafe_allow_html=True,
53
+ )
54
+
55
+ # --- Your App Content ---
56
+ st.set_page_config(page_title="Sticky Built-in Header", layout="wide")
57
+
58
+ st.sidebar.success("This is a sidebar.")
59
+ st.sidebar.button("Sidebar Button")
60
+
61
+ st.title("🎈 App with Sticky Built-in Header")
62
+
63
+ st.header("Main Content Area")
64
+ st.write(
65
+ "Scroll down to see Streamlit's own header (with the app title, status widget, "
66
+ "and hamburger menu/deploy button) remain fixed at the top of the page."
67
+ )
68
+ st.write(f"The header height is assumed to be around {HEADER_HEIGHT_REM}rem.")
69
+ st.write(f"The main content's top padding is set to {MAIN_CONTENT_PADDING_TOP_REM}rem to avoid overlap.")
70
+
71
+ st.info("Note: This relies on Streamlit's internal HTML structure (`data-testid='stHeader'`, `section.main`). Future Streamlit updates could potentially affect this.")
72
+
73
+ if st.button("Show some data"):
74
+ st.dataframe({
75
+ 'Column A': range(10),
76
+ 'Column B': [i * 2 for i in range(10)],
77
+ 'Column C': [str(i) * 3 for i in range(10)],
78
+ })
79
+
80
+ for i in range(50):
81
+ st.write(f"Scrollable content line {i + 1}. The header should stay visible.")
82
+
83
+ st.success("You've reached the end of the scrollable content!")
84
+
85
+
86
+
87
+
88
 
89
  #hide_streamlit_style = """
90
  # <style>