I have DatePickerRange and DataTable in my Dash, i need live-updating my DataTable when i changing my DatePickerRange. I have code:
dcc.DatePickerRange(
id = "date-picker-range",
start_date = ("2019-3-1"),
end_date_placeholder_text="Select a date!"
),
dash_table.DataTable(
id='table',
columns=[{"name": i, "id": i} for i in df.columns],
data=df.to_dict('records'),
I tried:
mask = (df['data'] > start_date) & (df['data'] <= end_date_placeholder_text)
df.loc[mask]
But it doesnt work: NameError: name 'start_date' is not defined
Where are you trying to update your DataTable? It should be in a callback function. Without knowing more about your code and application, the structure of the callback function should be something like this:
#define or import 'df' here
@app.callback(
dash.dependencies.Output('table', 'data'),
[dash.dependencies.Input('date-picker-range', 'start_date'),
dash.dependencies.Input('date-picker-range', 'end_date_placeholder_text')])
def update_output(start_date, end_date):
#or defined 'df' here
mask = (df['data'] > start_date) & (df['data'] <= end_date_placeholder_text)
return df.loc[mask].to_dict('records')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.