Question about date_input on sidebar

Hi guys,

I have a sidebar to select a date as filter, just like below:

unique_dates = sorted(list(set(dates)), reverse=True)
selected_date = st.sidebar.selectbox("Select a date", unique_dates, key='date_selector')

as you can see, the sibar date select opinion only showing dates in the ‘unique_dates’.

However, I was wondering if I can pass this parameter on the st.sidebar.date_input() as well?

like below for example:

Anyway to input my ‘unique_dates’ into this calendar, that only date in the ‘unique_dates’ will be black, others will shown as grey or something?

like in my case, since my ‘unique_dates’ doesnt have date ‘2023-06-11’, so the calendar on that date, will be grey and maybe unclickable.

thank you very much:)

Hi @kow

By default, the st.data_input() does not appear to support greying out specific dates. What is possible is specifying the date range via min_value and `max_value) parameters (st.date_input - Streamlit Docs). It may be possible to create an implementation but that may require creating a custom component (Create a Component - Streamlit Docs).

An alternative solution may be to have users select a date via st.date_input then perform a list comprehension to see if the selected date is available in the unique_dates variable. Next, use if-else conditions to print out a message to users whether the selected date is available or not.

Hope this helps!

Best regards,

@dataprofessor Thanks for your reply, I will try with your suggestion:P

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.