Hi Everyone,
Apologies for not finding a similar answer to this, but I have a Datatable where I select options from two drop downs and hit the submit button to update a Datatable (I query a redshift cluster via Pandas). Interestingly enough, the table will update the first time I hit the submit button, but will not update when a press the button again. Can someone explain to me what I am doing wrong?
#Layout
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Dropdown(
id='scenario_selection',
options=[
{'label': 'Scenario 1', 'value': 'Scenario 1'},
{'label': 'Scenario 2', 'value': 'Scenario 2'},
{'label': 'Scenario 3', 'value': 'Scenario 3'},
,
],
value=''
),
dcc.Dropdown(
id='time_period',
options=[
{'label': 'FY19', 'value': 'FY19'},
{'label': 'FY18', 'value': 'FY18'},
{'label': 'FY17', 'value': 'FY17'},
{'label': 'FY16', 'value': 'FY16'},
{'label': 'FY15', 'value': 'FY15'},
],
value=''
),
html.Button('Submit', id = 'button'),
html.Div(id = 'table'),
])
@app.callback(
dash.dependencies.Output("table", "children"),
[dash.dependencies.Input('button', 'n_clicks'),
dash.dependencies.Input('scenario_selection', "value"),
dash.dependencies.Input('time_period', "value")]
)
def update_table(n_clicks, scenario_selection, time_period):
if n_clicks:
df = download_data(str(scenario_selection), str(time_period)) #query redshift cluster, #returns Pandas dataframe
return html.Div([
dash_table.DataTable(
id = 'table',
columns=[{
"name": i, "id": i,
'deletable': True
} for i in df.columns],
data= df.to_dict("rows")
)
])
if __name__ == '__main__':
app.run_server(debug = True)