Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -559,51 +559,14 @@ if st.session_state.current_index > 0:
|
|
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 |
-
|
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 =
|
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 <=
|
605 |
-
|
606 |
-
st.
|
607 |
else:
|
608 |
st.info(f"{st.session_state.go_to} is not in the range of data.")
|
609 |
except ValueError:
|
@@ -614,8 +577,6 @@ with col2:
|
|
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>
|
|
|
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 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
563 |
def navigate_to_index():
|
564 |
try:
|
565 |
+
go_to_index = int(st.session_state.go_to)-1
|
|
|
566 |
# Check if the index is within the valid range
|
567 |
+
if 0 <= go_to_index < len(st.session_state.data):
|
568 |
+
st.session_state.current_index = go_to_index
|
569 |
+
st.experimental_rerun()
|
570 |
else:
|
571 |
st.info(f"{st.session_state.go_to} is not in the range of data.")
|
572 |
except ValueError:
|
|
|
577 |
with st.form(key="nav_form"):
|
578 |
st.number_input("Go to Page: ", key="go_to", format="%.0f")
|
579 |
st.form_submit_button("Go", on_click=navigate_to_index)
|
|
|
|
|
580 |
|
581 |
st.markdown(
|
582 |
"""<style>
|