I have a small one-page dash app, with a dash-ag-grid table based on some va, and a go.Scatter graph (lines+markers), which is also based on data from the same df. Please tell me how to make mapping so that when selecting an area on the graph, the table displays data only for the timestamp selected on this graph.
Grid:
def create_grid(df):
columnDefs=[{'headerName': col, 'field': col} for col in df.columns]
ag_grid = dag.AgGrid(
id="ag-grid",
rowData=df.to_dict("records"),
columnDefs=columnDefs,
)
return ag_grid
plot:
def plot(df, group_by, param, per=None):
group_by = 'timestamp'
fig = go.Figure()
cum_sum = df.groupby(group_by)[param].sum().reset_index()
fig.add_trace(go.Scatter(x=cum_sum[group_by],y=cum_sum[param],mode='lines',name=param,marker=dict(color=color)),)
for _, row in cum_sum.iterrows():
group = row[group_by_label]
fig.add_scatter(x=[group], y=[row[param]], mode='markers', name='',
showlegend=False,marker=dict(color=color),)
fig.update_layout(title='Title',xaxis=dict(type='category'),height=height,)
return fig
app:
app.layout = html.Div([
html.Div([grid]),
dcc.Graph(id='scatter',figure=fig1)])
You can use a callback in Dash.
Now, when you select an area on the scatter plot, the table will update to display data only for the selected timestamps.