Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -309,6 +309,41 @@ def navigate(index_change):
|
|
309 |
|
310 |
st.rerun()
|
311 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
|
313 |
def show_field(f: Field, index: int, data_collected):
|
314 |
if f.type not in INPUT_FIELD_DEFAULT_VALUES.keys():
|
@@ -567,6 +602,16 @@ if st.session_state.current_index > 0:
|
|
567 |
if 0 <= st.session_state.current_index < len(st.session_state.data):
|
568 |
st.write(f"Page {st.session_state.current_index + 1} out of {len(st.session_state.data)}")
|
569 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
570 |
st.markdown(
|
571 |
"""<style>
|
572 |
div[data-testid="InputInstructions"] {
|
|
|
309 |
|
310 |
st.rerun()
|
311 |
|
312 |
+
# Function to navigate to specific rows
|
313 |
+
def navigate_to_row(index):
|
314 |
+
st.session_state.current_index = index - 1
|
315 |
+
# only works consistently if done before rerun
|
316 |
+
js = '''
|
317 |
+
<script>
|
318 |
+
var body = window.parent.document.querySelector(".main");
|
319 |
+
|
320 |
+
body.scrollTop = 0;
|
321 |
+
window.scrollY = 0;
|
322 |
+
</script>
|
323 |
+
'''
|
324 |
+
st.components.v1.html(js, height=0)
|
325 |
+
# https://discuss.streamlit.io/t/click-twice-on-button-for-changing-state/45633/2
|
326 |
+
|
327 |
+
# disable text input enter to submit
|
328 |
+
# https://discuss.streamlit.io/t/text-input-how-to-disable-press-enter-to-apply/14457/6
|
329 |
+
components.html(
|
330 |
+
"""
|
331 |
+
<script>
|
332 |
+
const inputs = window.parent.document.querySelectorAll('input');
|
333 |
+
inputs.forEach(input => {
|
334 |
+
input.addEventListener('keydown', function(event) {
|
335 |
+
if (event.key === 'Enter') {
|
336 |
+
event.preventDefault();
|
337 |
+
}
|
338 |
+
});
|
339 |
+
});
|
340 |
+
</script>
|
341 |
+
""",
|
342 |
+
height=0
|
343 |
+
)
|
344 |
+
|
345 |
+
st.rerun()
|
346 |
+
|
347 |
|
348 |
def show_field(f: Field, index: int, data_collected):
|
349 |
if f.type not in INPUT_FIELD_DEFAULT_VALUES.keys():
|
|
|
602 |
if 0 <= st.session_state.current_index < len(st.session_state.data):
|
603 |
st.write(f"Page {st.session_state.current_index + 1} out of {len(st.session_state.data)}")
|
604 |
|
605 |
+
def navigate_to_index():
|
606 |
+
if st.session_state.go_to-1 in range(len(st.session_state.data)):
|
607 |
+
navigate_to_row(st.session_state.go_to)
|
608 |
+
else:
|
609 |
+
st.info(f"{st.session_state.go_to} not in range of data.")
|
610 |
+
|
611 |
+
with st.form(key="nav_form"):
|
612 |
+
st.number_input("Go to Page: ", key="go_to")
|
613 |
+
st.form_submit_button("Go", on_click=navigate_to_index)
|
614 |
+
|
615 |
st.markdown(
|
616 |
"""<style>
|
617 |
div[data-testid="InputInstructions"] {
|