So, my issue is pretty simple.
Let’s say you have a calendar, you have a selectbox in which elements are
0 - Monday,
1 - Tuesday,
…
30 - Someday
Now, you want to be able to search for a specific day (st.selectbox does it natively with the keyboard), and also you want to have 2 buttons, previous and next that help you navigate in between the calendar. I want the buttons to change the label of the selectbox.
My solution is below, but I have some issues. In particular, if I do a combination of filtering the list with something like “Sund”, pressing a button, and changing the page, everything doesn’t work anymore, the indices go to 0 or exceed the maximum of the list length. Do you have any workaround?
import streamlit as st
calendar_clmns = st.columns([1, 5, 1])
if "curr_day" not in st.session_state:
st.session_state["curr_day"] = 0
with calendar_clmns[0]:
# Prev
if st.button("Precedente", use_container_width=True):
st.session_state["curr_day"] = max(0, st.session_state["curr_day"] - 1)
with calendar_clmns[2]:
# Succ
if st.button("Successivo", use_container_width=True):
st.session_state["curr_day"] = min(30, st.session_state["curr_day"] + 1)
with calendar_clmns[1]:
selected_option = st.selectbox("Seleziona il possesso da visualizzare:",
index=st.session_state["curr_day"],
options=[str(i) + " - " + day[i] for i in range(31)],
label_visibility="collapsed")
selected_day = int(selected_option.split(" - ")[0])
if selected_day != st.session_state["curr_day"]:
st.session_state["curr_day"] = selected_day