import streamlit as st
from streamlit_datetime_range_picker import datetime_range_picker
# Use datetime_range_picker to create a datetime range picker
datetime_string = datetime_range_picker(start=-30, end=0, unit='minutes', key='range_picker',
picker_button={'is_show': True, 'button_name': 'Refresh last 30min'})
if datetime_string is not None:
start_datetime = datetime_string[0]
end_datetime = datetime_string[1]
Parameter
start: Default start time, type: int, default value: -30.
end: Default end time, type: int, default value: 0.
unit: Default time unit, type: str, options: milliseconds, seconds, minutes, hours, days, weeks, months, years.
key: Picker key, default value: None.
picker_button: Refresh button configuration, type: {âis_showâ: bool, âbutton_nameâ: str}, default values: False and âRefresh last 30minâ. When the button is clicked, it refreshes the selected time range.
The return value of datetime_range_picker is of type str.
Thanks @imdreamer2018 ! Would it be possible to only use the picker to select one date and time, and not a range? I donât know if it is clear, but it would allow us to not use the st.date_input and st.time_input separately and simply use the calendar as it is in your picker.
Hi,
date picker feature has been implement in new version.
install
pip install streamlit-date-picker
Usage
import streamlit as st
from streamlit_date_picker import date_range_picker, PickerType, Unit, date_picker
st.title('Streamlit Date Picker')
# Use date_range_picker to create a datetime range picker
st.subheader('Date Range Picker')
date_range_string = date_range_picker(picker_type=PickerType.time.string_value,
start=-30, end=0, unit=Unit.minutes.string_value,
key='range_picker',
refresh_button={'is_show': True, 'button_name': 'Refresh last 30min',
'refresh_date': -30,
'unit': Unit.minutes.string_value})
if date_range_string is not None:
start_datetime = date_range_string[0]
end_datetime = date_range_string[1]
st.write(f"Date Range Picker [{start_datetime}, {end_datetime}]")
st.subheader('Date Picker')
# Use date_picker to create a date picker
date_string = date_picker(picker_type=PickerType.time.string_value, value=0, unit=Unit.days.string_value,
key='date_picker')
if date_string is not None:
st.write('Date Picker: ', date_string)
Is there a way to modify the end time to be different than now (or 0) when the refresh button is clicked?
Currently, with a refresh_date of -30 the refreshed_end_date would be 0 so the refresh period is only for 30min. I would like that when I click on the refresh button, the widget is reset to a 24h period starting from now, is it possible?
I tried to access and modify the different files directly but with no success
Thank you for your reply, but isnât possible to set refresh_date to 0 and set the end 24h later? I do not consider events in the past in my application so refreshing to a past period isnât really useful
@Girish Hi,
This components has default value for option. I donât know âis there any option to use the preset as well?â could your please give me more detail?
one another issue is that, the component is not getting overlapped with the other component while the datepicker is shown. instead it is creating a space between the the other component as show in the image for refrence. it will be great if u can fix it, which will probably help user experience.
There is a bugg that causes the date-range components to flicker with the introduction of streamlit version 1.32.0. I managed to solve the issue by downgrading to streamlit 1.32.0.
A great component that is more flexible than the official component. When I first used it, I discovered the issue of component loop refresh. I checked the page structure code and found that it endlessly generated <style></style> style files until the browser crashed.
It would be great if this problem could be solved.
Thank you.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking âAccept allâ, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.