I want my dash app to take slider input value to change a variable through a function and then change the marker colour variable only.
I've been working at this code for awhile. Very close to finally getting a prototype. The only thing left is this variable changing with the slider. I just need marker dictionary sub function colour to change with the slider value changing in conjunction with the functions I've created. The function works by itself.
This is the code currently.
The first section is the layout dictionaries that dictate the styling of the map.
# Layouts
layout_map = dict(
autosize=True,
height=500,
font=dict(color="#191A1A"),
titlefont=dict(color="#191A1A", size='18'),
margin=dict(
l=35,
r=35,
b=35,
t=45
),
hovermode="closest",
plot_bgcolor='#fffcfc',
paper_bgcolor='#fffcfc',
legend=dict(font=dict(size=16), orientation='h'),
title='Freeway Detectors',
mapbox=dict(
accesstoken=mapbox_access_token,
style="dark",
center=dict(
lon=145.061,
lat=-37.865
),
zoom=13,
)
)
# Marker
def datatime(t):
heat = hf.filter(items = [t], axis=0).T.drop("index")
return heat[t]
heat = datatime(20)
marker = dict(id = 'layout-mark',
size=15,
color=heat,
colorscale='YlOrRd',
opacity=.8,
showscale=True,
cmax=2000,
cmin=0)
This is the app section with only the useful parts included.
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
.....
dcc.Graph(
id='graph',
figure={
'data': [{
'lat': mf.Y,
'lon': mf.X,
'type': 'scattermapbox',
'marker': marker
}],
'layout': layout_map
}
)
....
dcc.Slider(
id = "Slider",
marks={i: 'Hour {}'.format(i) for i in range(0, 24)},
min=mintime / 4,
max=maxtime / 4,
step=.01,
value=0,
)
], style={"padding-bottom": '50px', "padding-right": '50px', "padding-left": '50px', "padding-top": '50px'}),
....
@app.callback(
Output('graph', 'figure'),
[Input('Slider', 'value')])
def update_figure(selected_time):
heat = datatime(slider_value)
return heat
from input data from slider to change marker colour
No comments:
Post a Comment