Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -309,45 +309,6 @@ def navigate(index_change):
|
|
309 |
|
310 |
st.rerun()
|
311 |
|
312 |
-
# Function to navigate to specific rows
|
313 |
-
def navigate_to_row(index):
|
314 |
-
if 0 <= index < len(st.session_state.data):
|
315 |
-
st.session_state.current_index = index
|
316 |
-
# only works consistently if done before rerun
|
317 |
-
js = '''
|
318 |
-
<script>
|
319 |
-
var body = window.parent.document.querySelector(".main");
|
320 |
-
|
321 |
-
body.scrollTop = 0;
|
322 |
-
window.scrollY = 0;
|
323 |
-
</script>
|
324 |
-
'''
|
325 |
-
st.components.v1.html(js, height=0)
|
326 |
-
# https://discuss.streamlit.io/t/click-twice-on-button-for-changing-state/45633/2
|
327 |
-
|
328 |
-
# disable text input enter to submit
|
329 |
-
# https://discuss.streamlit.io/t/text-input-how-to-disable-press-enter-to-apply/14457/6
|
330 |
-
components.html(
|
331 |
-
"""
|
332 |
-
<script>
|
333 |
-
const inputs = window.parent.document.querySelectorAll('input');
|
334 |
-
inputs.forEach(input => {
|
335 |
-
input.addEventListener('keydown', function(event) {
|
336 |
-
if (event.key === 'Enter') {
|
337 |
-
event.preventDefault();
|
338 |
-
}
|
339 |
-
});
|
340 |
-
});
|
341 |
-
</script>
|
342 |
-
""",
|
343 |
-
height=0
|
344 |
-
)
|
345 |
-
|
346 |
-
#st.rerun()
|
347 |
-
else:
|
348 |
-
st.error("Index out of range.")
|
349 |
-
|
350 |
-
|
351 |
def show_field(f: Field, index: int, data_collected):
|
352 |
if f.type not in INPUT_FIELD_DEFAULT_VALUES.keys():
|
353 |
st.session_state.following_mandatory = False
|
@@ -594,25 +555,57 @@ else:
|
|
594 |
if st.session_state.current_index > 0:
|
595 |
if st.button("Previous"):
|
596 |
navigate(-1)
|
597 |
-
#if st.button("Last edited instance"):
|
598 |
-
# go_to_index = get_start_index()
|
599 |
-
# navigate_to_row(go_to_index)
|
600 |
|
601 |
if 0 <= st.session_state.current_index < len(st.session_state.data):
|
602 |
st.write(f"Page {st.session_state.current_index + 1} out of {len(st.session_state.data)}")
|
603 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
604 |
def navigate_to_index():
|
605 |
try:
|
606 |
-
go_to_index = int(st.session_state.go_to)
|
607 |
-
|
608 |
# Check if the index is within the valid range
|
609 |
-
if
|
610 |
-
|
611 |
-
elif 0 <= go_to_index < len(st.session_state.data):
|
612 |
st.session_state.go_to = 0
|
613 |
-
navigate_to_row(go_to_index)
|
614 |
else:
|
615 |
-
st.info(f"{
|
616 |
except ValueError:
|
617 |
st.error("The page number must be an integer.")
|
618 |
|
@@ -621,8 +614,8 @@ with col2:
|
|
621 |
with st.form(key="nav_form"):
|
622 |
st.number_input("Go to Page: ", key="go_to", format="%.0f")
|
623 |
st.form_submit_button("Go", on_click=navigate_to_index)
|
624 |
-
go_to_index = get_start_index()
|
625 |
-
st.form_submit_button("Direct to last updated instance", on_click=navigate_to_row(go_to_index))
|
626 |
|
627 |
st.markdown(
|
628 |
"""<style>
|
|
|
309 |
|
310 |
st.rerun()
|
311 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
def show_field(f: Field, index: int, data_collected):
|
313 |
if f.type not in INPUT_FIELD_DEFAULT_VALUES.keys():
|
314 |
st.session_state.following_mandatory = False
|
|
|
555 |
if st.session_state.current_index > 0:
|
556 |
if st.button("Previous"):
|
557 |
navigate(-1)
|
|
|
|
|
|
|
558 |
|
559 |
if 0 <= st.session_state.current_index < len(st.session_state.data):
|
560 |
st.write(f"Page {st.session_state.current_index + 1} out of {len(st.session_state.data)}")
|
561 |
|
562 |
+
# Function to navigate to specific rows
|
563 |
+
#def navigate_to_row(index):
|
564 |
+
# if 0 <= index < len(st.session_state.data):
|
565 |
+
# st.session_state.current_index = index
|
566 |
+
# # only works consistently if done before rerun
|
567 |
+
# js = '''
|
568 |
+
# <script>
|
569 |
+
# var body = window.parent.document.querySelector(".main");
|
570 |
+
#
|
571 |
+
# body.scrollTop = 0;
|
572 |
+
# window.scrollY = 0;
|
573 |
+
# </script>
|
574 |
+
# '''
|
575 |
+
# st.components.v1.html(js, height=0)
|
576 |
+
# # https://discuss.streamlit.io/t/click-twice-on-button-for-changing-state/45633/2
|
577 |
+
#
|
578 |
+
# # disable text input enter to submit
|
579 |
+
# # https://discuss.streamlit.io/t/text-input-how-to-disable-press-enter-to-apply/14457/6
|
580 |
+
# components.html(
|
581 |
+
# """
|
582 |
+
# <script>
|
583 |
+
# const inputs = window.parent.document.querySelectorAll('input');
|
584 |
+
# inputs.forEach(input => {
|
585 |
+
# input.addEventListener('keydown', function(event) {
|
586 |
+
# if (event.key === 'Enter') {
|
587 |
+
# event.preventDefault();
|
588 |
+
# }
|
589 |
+
# });
|
590 |
+
# });
|
591 |
+
# </script>
|
592 |
+
# """,
|
593 |
+
# height=0
|
594 |
+
# )
|
595 |
+
#
|
596 |
+
# st.rerun()
|
597 |
+
# else:
|
598 |
+
# st.error("Index out of range.")
|
599 |
def navigate_to_index():
|
600 |
try:
|
601 |
+
go_to_index = st.session_state.current_index - int(st.session_state.go_to)
|
602 |
+
go_back_by = st.session_state.current_index - go_to_index
|
603 |
# Check if the index is within the valid range
|
604 |
+
if 0 <= go_back_by < len(st.session_state.data):
|
605 |
+
navigate_to_row(-1*int(go_back_by))
|
|
|
606 |
st.session_state.go_to = 0
|
|
|
607 |
else:
|
608 |
+
st.info(f"{st.session_state.go_to} is not in the range of data.")
|
609 |
except ValueError:
|
610 |
st.error("The page number must be an integer.")
|
611 |
|
|
|
614 |
with st.form(key="nav_form"):
|
615 |
st.number_input("Go to Page: ", key="go_to", format="%.0f")
|
616 |
st.form_submit_button("Go", on_click=navigate_to_index)
|
617 |
+
# go_to_index = get_start_index()
|
618 |
+
# st.form_submit_button("Direct to last updated instance", on_click=navigate_to_row(go_to_index))
|
619 |
|
620 |
st.markdown(
|
621 |
"""<style>
|