Hi Dash Community,
I am having trouble labeling the marks on a range slider component.
The dict that I am feeding to the “marks” attribute is being formed correctly and I can’t tell what’s happening.
The simple example below should demonstrate what is wrong.
Thank you!
import dash
import dash_core_components as dcc
import dash_html_components as html
import datetime as dt
from dateutil.relativedelta import relativedelta
epoch = dt.datetime.utcfromtimestamp(0)
def unix_time_millis(dt):
return (dt - epoch).total_seconds() #* 1000.0
def get_marks_from_start_end(start, end):
result =
marks={}
current = start
while current <= end:
result.append(current)
current += relativedelta(days=1)
for i in result:
marks[unix_time_millis(i)] = {‘label’:i.strftime(‘%b %d, %Y - %H:%M:%S’)}
return marks
app = dash.Dash()
app.layout = html.Div(children=[
html.Div([
dcc.RangeSlider(
id = ‘datetime_RangeSlider’,
allowCross=False,
updatemode = ‘mouseup’, #don’t let it update till mouse released
min = unix_time_millis(dt.datetime(2017,10,17)),
max = unix_time_millis(dt.datetime(2017,10,19)),
value = [unix_time_millis(dt.datetime(2017,10,17)),
unix_time_millis(dt.datetime(2017,10,19))],
marks=get_marks_from_start_end(dt.datetime(2017,10,17),
dt.datetime(2017,10,19))
)
]
)
]
)
if name == ‘main’:
app.run_server(debug=False)