Date input range - index error while selecting

I am running into an issue in one of my apps with a date input widget. For this app, the widget allows the user to input a date range which then controls a bar chart in the app.

One thing I have noticed is that when selecting the dates from the calendar the app re-runs upon selection of the first date (before the second date is selected) which causes an index error in my code every time. When the user selects the second date everything runs smoothly, but it is not the best user experience to get a full page error in the middle of selecting their desired date range.

Any tips on how to avoid app execution until a complete selection is made?



Attaching some screenshots to demonstrate the issue.

Hi @joe_loftus, welcome to the Streamlit community!

Depending on how your code is structured, you could do something to the effect of:


start_date, end_date = st.date_input(...)

if start_date and end_date:
    do_something()

That way, the code won’t run unless you have a start and end date.

Best,
Randy