Update pages/type_text.py
Browse files- pages/type_text.py +31 -27
pages/type_text.py
CHANGED
@@ -47,40 +47,46 @@ def convert_json(df:pd.DataFrame):
|
|
47 |
#st.json(json_string, expanded=True)
|
48 |
return json_string
|
49 |
|
50 |
-
def
|
51 |
-
#
|
52 |
js_code = """
|
53 |
<script>
|
54 |
-
//
|
55 |
-
|
56 |
-
//
|
57 |
-
const
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
} else {
|
64 |
-
// Fallback to scrolling the entire page
|
65 |
-
window.parent.scrollTo(0, streamlitDoc.body.scrollHeight);
|
66 |
}
|
67 |
-
}
|
68 |
|
69 |
-
//
|
70 |
-
|
|
|
|
|
71 |
|
72 |
-
//
|
73 |
-
|
|
|
|
|
|
|
|
|
74 |
|
75 |
-
//
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
77 |
</script>
|
78 |
"""
|
79 |
|
80 |
-
#
|
81 |
-
|
82 |
-
st.components.v1.html(html, height=0)
|
83 |
-
|
84 |
|
85 |
#df_chapters = pd.read_csv("SBS_V2_0/Chapter_Index_Rows.csv")
|
86 |
df_chapters = pd.read_csv("SBS_V2_0/Chapter_Index_Rows_with_total.csv")
|
@@ -141,8 +147,6 @@ dfALL = pd.DataFrame.from_dict(dictA)
|
|
141 |
|
142 |
#INTdesc_input = st.text_input("Type internal description", key="user_input")
|
143 |
INTdesc_input = st.text_input(r"$\textsf{\Large Type internal description}$", key="user_input")
|
144 |
-
auto_scroll_to_bottom()
|
145 |
-
|
146 |
placeholder, centerL_column, centerR_column, right_column = st.columns(4)
|
147 |
#placeholder_clicked = placeholder.button("Perform some action", key="user_placeholder")
|
148 |
right_column.button("Reset description", on_click=on_click)
|
|
|
47 |
#st.json(json_string, expanded=True)
|
48 |
return json_string
|
49 |
|
50 |
+
def scroll_to_bottom():
|
51 |
+
# This script uses Streamlit's message system to ensure proper timing
|
52 |
js_code = """
|
53 |
<script>
|
54 |
+
// Function to scroll to bottom
|
55 |
+
function scrollToBottom() {
|
56 |
+
// This targets Streamlit's specific structure
|
57 |
+
const mainContainer = window.parent.document.querySelector('.stApp');
|
58 |
+
if (mainContainer) {
|
59 |
+
mainContainer.scrollTo({
|
60 |
+
top: mainContainer.scrollHeight,
|
61 |
+
behavior: 'smooth'
|
62 |
+
});
|
|
|
|
|
|
|
63 |
}
|
64 |
+
}
|
65 |
|
66 |
+
// Use MutationObserver to detect when content is added
|
67 |
+
const observer = new MutationObserver((mutations) => {
|
68 |
+
scrollToBottom();
|
69 |
+
});
|
70 |
|
71 |
+
// Start observing the document body for changes
|
72 |
+
const streamlitDoc = window.parent.document;
|
73 |
+
observer.observe(streamlitDoc.body, {
|
74 |
+
childList: true,
|
75 |
+
subtree: true
|
76 |
+
});
|
77 |
|
78 |
+
// Initial scroll and disconnect after some time
|
79 |
+
scrollToBottom();
|
80 |
+
setTimeout(() => {
|
81 |
+
observer.disconnect();
|
82 |
+
// One final scroll
|
83 |
+
scrollToBottom();
|
84 |
+
}, 1000);
|
85 |
</script>
|
86 |
"""
|
87 |
|
88 |
+
# Use unsafe_allow_html to inject JavaScript
|
89 |
+
st.markdown(js_code, unsafe_allow_html=True)
|
|
|
|
|
90 |
|
91 |
#df_chapters = pd.read_csv("SBS_V2_0/Chapter_Index_Rows.csv")
|
92 |
df_chapters = pd.read_csv("SBS_V2_0/Chapter_Index_Rows_with_total.csv")
|
|
|
147 |
|
148 |
#INTdesc_input = st.text_input("Type internal description", key="user_input")
|
149 |
INTdesc_input = st.text_input(r"$\textsf{\Large Type internal description}$", key="user_input")
|
|
|
|
|
150 |
placeholder, centerL_column, centerR_column, right_column = st.columns(4)
|
151 |
#placeholder_clicked = placeholder.button("Perform some action", key="user_placeholder")
|
152 |
right_column.button("Reset description", on_click=on_click)
|