external_stylesheets = [‘https://codepen.io/chriddyp/pen/bWLwgP.css’]
app = dash.Dash(name, external_stylesheets=external_stylesheets)
app.layout = html.Div([
html.P(html.Div(html.H3(‘Reddit Dashboard’))),
html.P(html.Button(‘Sort: New’, id=‘new’, type=‘submit’),
style={‘margin-top’: ‘10px’, ‘margin-bottom’: ‘30px’, ‘display’: ‘inline-block’}),
html.P(html.Button(‘Sort: Hot’, id=‘hot’),
style={‘margin-left’: ‘30px’, ‘display’: ‘inline-block’}),
html.P(html.Button(‘Sort: Rising’, id=‘rising’),
style={‘margin-left’: ‘30px’, ‘display’: ‘inline-block’}),
html.P(html.Button(‘Sort: Top’, id=‘top’),
style={‘margin-left’: ‘30px’, ‘display’: ‘inline-block’}),
html.P(html.Button(‘Sort: Controversial’, id=‘controversial’),
style={‘margin-left’: ‘30px’, ‘display’: ‘inline-block’}),dash_table.DataTable( id='table_002' , style_cell_conditional=[ ] , style_data={ 'text-align': 'center' } , style_table={ } , columns=[{"name": i, "id": i} for i in grouped_df.columns] , fixed_rows={'headers': True, 'data': 0} , data=grouped_df.to_dict('records') ), dash_table.DataTable( id='table' , style_cell_conditional=[ ] , style_data={ 'text-align': 'center' } , style_table={ } , style_data_conditional=[ ] , columns=[{"name": i, "id": i} for i in df.columns] , fixed_rows={'headers': True, 'data': 0} , data=df.to_dict('records') ), dcc.Store(id='intermediate-value')
])
@app.callback(Output(‘intermediate-value’, ‘data’),
Input(‘new’, ‘n_clicks’),
Input(‘hot’, ‘n_clicks’),
Input(‘rising’, ‘n_clicks’),
Input(‘top’, ‘n_clicks’),
Input(‘controversial’, ‘n_clicks’))
def update_data(new, hot, rising, top, controversial):
posts_df_updated = posts_dfbutton_id = [p['prop_id'] for p in dash.callback_context.triggered][0] if 'new' in button_id: posts_df_updated = df_reddit(reddit.subreddit('cryptocurrency').new(limit=posts_limit)) elif 'hot' in button_id: posts_df_updated = df_reddit(reddit.subreddit('cryptocurrency').hot(limit=posts_limit)) elif 'rising' in button_id: posts_df_updated = df_reddit(reddit.subreddit('cryptocurrency').rising(limit=posts_limit)) elif 'top' in button_id: posts_df_updated = df_reddit(reddit.subreddit('cryptocurrency').top("day", limit=posts_limit)) elif 'controversial' in button_id: posts_df_updated = df_reddit(reddit.subreddit('cryptocurrency').controversial("day", limit=posts_limit)) dff = posts_df_updated.copy() return dff.to_json(date_format='iso', orient='split')
@app.callback(Output(‘table_002’, ‘data’),
Input(‘intermediate-value’, ‘data’))
def update_data_002(data):
df_scores = df_attention(data)return df_scores.to_dict('records')
if name == ‘main’:
app.run_server(debug=True, port=8050)
Hello, I have a main table which get populated from the reddit api (def update_data) and I want the output to go towards updating the table on the app and sending data to my second update function (def_update_data_002) which does calculation on the data and updates a second table.
How can I have the first update function send data to the table and the second function?
Thanks.