arnaudmiribel / streamlit-extras

Discover, try, install and share Streamlit re-usable bits we call "extras"!
https://extras.streamlit.app
Apache License 2.0
715 stars 123 forks source link

🐛 [BUG] - date_range_picker() usage in st.form() #167

Closed sametsoekel closed 11 months ago

sametsoekel commented 1 year ago

Description

Hi,

Works like a charm in the standalone way, but couldn't make it happen in st.form()

Reproduction steps


import streamlit as st
from streamlit_extras.mandatory_date_range import date_range_picker

form = st.form(key="user_form_analysis")

endeks = form.selectbox(
    'Pick a symbol',
    ('A','B','C'))

obs_horizon = form.date_range_picker("Select a date range")

get_anaylsis_buton = form.form_submit_button('Get')

Screenshots

image

Logs

No response

Version of streamlit

1.20.0

Version of streamlit-extras

0.3.0

arnaudmiribel commented 11 months ago

Hey @sametsoekel!

Sorry for the late answer.

To make it work within a form, you should use the with: notation instead of calling with the streamlit namespace. Indeed, the date_range_picker is not part of the official streamlit namespace.

import streamlit as st 
from streamlit_extras.mandatory_date_range import date_range_picker

form = st.form(key="foo")

form.selectbox("Bar", list("abcd"))
with form:  # <-  see this
    date_range_picker("Select a date range")
form.form_submit_button()

But to be fair, the behavior won't be ideal when used in a form, see demo:

image