I just started using Dash and plotly today and I am making a simple dashboard app where I have a map with some locations marked and some time series data associated with each location and I show the map as a figure and an associated time series as a figure. So, I have setup as follows:
def get_sensor_info(filename):
frame = pd.read_csv(filenam)
frame.drop_duplicates('sensor_id', inplace=True)
return frame['latitude'].tolist(), frame['longitude'].tolist(), frame['sensor_id'].tolist()
lat, lon, sensors = get_sensor_info('sensors.csv')
mapbox_access_token = open(".mapbox_token").read()
fig = go.Figure(go.Scattermapbox(lat=lat, lon=lon, text=desc, marker=go.scattermapbox.Marker(size=14, opacity=0.7)))
fig.update_layout(
autosize=True,
hovermode='closest',
mapbox=dict(
accesstoken=mapbox_access_token,
bearing=0,
center=dict(
lat=center_lat,
lon=center_lon
),
zoom=8
)
)
# generate some random pandas dataframe
time_series = px.line(df, x=df.index, y = df.columns)
app = dash.Dash()
app.layout = html.Div([
dcc.Graph(id='map', figure=fig),
dcc.Graph(id='timeseries', figure=time_series)
])
Now my question is given this sorrt of setup, how can I basically capture the event when a user clicks on a marker on the map. Ideally, I would want to get the sensor ID from this event and then update the time series line plot after retrieving this sensor data.
I tried something like:
@app.callback(
Output('click-data', 'children'),
[Input('map', 'clickData')])
def display_click_data(clickData):
return json.dumps(clickData, indent=2)
However, this does not seem to return anything.