I want to create a graph, current_ratio_stocks
within a pop up, a modal. This graph needs to know some information from the the active_cell
that fired the modal.
@app.callback(Output('modal', 'children'),
[Input('table', 'active_cell'),
Input('close', 'n_clicks')],
# [State('modal', 'is_open')]
)
def set_content(active_cell, n_clicks):
if active_cell is not None:
row = df.iloc[[active_cell.get("row")]]
name = row['Name']
ticker = row['Ticker']
return [
dbc.ModalHeader(name),
dbc.ModalBody(
html.Div([
html.Div([
html.H6('Sales', style={'textAlign': 'center', 'padding': 10}),
html.P(update_earnings(ticker), id="sales_stocks", style={'textAlign': 'center', 'padding': 10})
], className='pretty_container four columns'),
html.Div([
html.H5('Current ratio', style={'textAlign': 'center', 'padding': 10}),
dcc.Graph(id="current_ratio_stocks"),
], className='pretty_container seven columns')
]), className='pretty_container twelve columns'),
dbc.ModalFooter(dbc.Button("Close", id="close")),
]
So far Iām doing:
@app.callback(
Output('current_ratio_stocks', 'figure'),
[Input('table', 'active_cell')])
def update_current_ratio(active_cell):
df = pd.read_csv(DATA_PATH + 'tickers_september_2017_red.csv')
row = df.iloc[[active_cell.get("row")]]
ticker = row['Ticker'].values[0]
...
return fig
But that leads to the situation where I have to wait for active_cell
to be activated twice in order to show up.