我正在使用plotly dash应用程序,并且试图创建一个月份范围滑块以显示在我的前端
下面是我为使范围滑块编写的代码。我无法弄清楚的是,如何限制范围滑块最多只能选择两个值。
maxmarks = 12
tday = pd.Timestamp.today() # gets timestamp of today
m1date = tday.month # first month on slider
datelist = pd.date_range(tday, periods=maxmarks, freq='M') # list of months as dates
dlist = pd.DatetimeIndex(datelist).normalize()
tags = {} # dictionary relating marks on slider to tags. tags are shown as "Apr', "May', etc
datevalues = {} # dictionary relating mark to date value
x = m1date
for i in dlist:
tags[x] = (i + DateOffset(months=0)).strftime('%b') # gets the string representation of next month ex:'Apr'
datevalues[x] = i
x = x + 1
if x >= 13:
x = x - 12
html.Div([
dcc.RangeSlider(
id='month_slider',
# updatemode='drag',
# count=1,
min=1,
max=maxmarks,
step=1,
value=[maxmarks - 1, maxmarks],
marks=tags,
pushable=1
),
我想要的是前端,用户在滑块上选择的时间不能超过两个月。
我希望有人能帮助解决这个问题。
非常感谢!