First time working with DashTable. I am receiving an error:
“A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead”
The table populates just fine (via the same data transformations in the callback) when I run it within the layout. The error occurs when I remove the column and data definition from the table and try to update the table with new data.
layout = html.Div([
html.Div([html.Button('Refresh Data', id='refresh-data')]),
html.Div([
tbl.DataTable(
id='table',
# columns=[{"name": i, "id": i} for i in dft.columns],
# data=dft.to_dict("rows"),
)
]),
html.Div(
dcc.Checklist(
id='yearlist',
options=[
{'label': '2016', 'value': 2016},
{'label': '2017', 'value': 2017},
{'label': '2018', 'value': 2018},
{'label': '2019', 'value': 2019}
],
values=[2018,2019]
)
),
dcc.Graph(id='indicator-graphic'),
html.Div(id='last-update', style={'display': 'none'})
])
@app.callback(
Output('table','children'),
[Input('last-update','children')])
def update_table(value):
dft = df[df.tradedate > datetime.now() - pd.to_timedelta("15day")]
dft.tradedate = dft.tradedate.astype(str)
dft = dft.pivot_table(values = 'volume', index =['fundamentaldetail'],columns='tradedate').reset_index('fundamentaldetail')
return {
'columns': [{"name": i, "id": i} for i in dft.columns],
'data': dft.to_dict("rows"),
}