Hi guys,
I’m bulding a dashboard that get inputs from user and based on it data appears on a map related to user inputs
when I made a callback that changes the data based on user’s inputs the changes don’t appear unless I clicked in right click >> inspect anyone can help why this is happening?
app.Layout = html.Div([
dcc.Graph(id='moves_map',
animate=True,
style={'marginTop': '20'})
])
map_layout = dict(
clickmode="event+select",
showlegend=True,
autosize=True,
hovermode="closest",
margin=dict(l=0, r=0, t=0, b=0),
mapbox=go.layout.Mapbox(
accesstoken=mapbox_access_token,
bearing=0,
center=go.layout.mapbox.Center(lat=21.3891, lon=39.8579),
pitch=0,
zoom=10,
),
legend=dict(
bgcolor="#1f2c56",
orientation="h",
font=dict(color="white"),
x=0,
y=0,
yanchor="bottom",
),
)
def gen_moves_map(data):
groups = data.groupby('date')
data_map =[]
for name,group in groups:
d = {
"type": "scattermapbox",
"lat": group['lat'].values,
"lon": group['long'].values,
"mode": "markers+lines",
"name": name,
"marker": {
"size": 6,
"opacity": 0.5
}
}
data_map.append(d)
# groupby returns a dictionary mapping the values of the first field
# 'classification' onto a list of record dictionaries with that
# classification value.
return {
"data": data_map,
"layout": map_layout
}
@app.callback(
Output('moves_map', 'figure'),
[Input('button', 'n_clicks')],
[
State('bus_no', 'value'),
State('date','value'),
State('from','value'),
State('to','value')
])
def update_moves(n_clicks, bus_no,date,_from,_to):
from_str = date+' '+_from
to_str = date+' '+_to
from_date = datetime.datetime.strptime(from_str, '%d/%m/%Y %H:%M')
to_date = datetime.datetime.strptime(to_str, '%d/%m/%Y %H:%M')
data = getMapData(bus_no,from_date,to_date)
return gen_moves_map(data)