Hello!
Thanks, that solved that issue, but the code still doesn’t work. Do you mind taking a look at my callbacks and seeing why? Im new to this so expect basic errors.
before callbacks
app = dash.Dash(name)
df = pd.read_csv(‘data/dashboard_data.csv’)
PAGE_SIZE = 10
app.layout [see above]
callbacks
@app.callback(
Output(‘table-sorting-filtering’, ‘data’),
[Input(‘table-sorting-filtering’, “page_current”),
Input(‘table-sorting-filtering’, “page_size”),
Input(‘table-sorting-filtering’, ‘sort_by’),
Input(‘table-sorting-filtering’, ‘filter_query’),
Input(‘interval_component’, ‘n_intervals’),
Input(‘my-date-picker-range’, ‘start_date’),
Input(‘my-date-picker-range’, ‘end_date’)])def update_table(page_current, page_size, sort_by, filter, n_intervals, start_date, end_date):
filtering_expressions = filter.split(’ && ')
dff = df
for filter_part in filtering_expressions:
col_name, operator, filter_value = split_filter_part(filter_part)
if operator in (‘eq’, ‘ne’, ‘lt’, ‘le’, ‘gt’, ‘ge’):
# these operators match pandas series operator method names
dff = dff.loc[getattr(dff[col_name], operator)(filter_value)]
elif operator == ‘contains’:
dff = dff.loc[dff[col_name].str.contains(filter_value)]
elif operator == ‘datestartswith’:
# this is a simplification of the front-end filtering logic,
# only works with complete fields in standard format
dff = dff.loc[dff[col_name].str.startswith(filter_value)]
if len(sort_by):
dff = dff.sort_values(
[col[‘column_id’] for col in sort_by],
ascending=[
col[‘direction’] == ‘asc’
for col in sort_by
],
inplace=False
)
return dff.iloc[
page_current*page_size:(page_current+ 1)*page_size
].to_dict(‘records’)def update_rows(n_intervals, n_clicks):
data = pd.read_csv(‘data/dashboard_data.csv’)
dict = data.to_dict(‘records’)
return dictdef update_data(start_date, end_date):
df2 = df.loc[start_date: end_date]
data = df2.to_dict(“rows”)return data
@app.callback(
Output(‘output-container-date-picker-range’, ‘children’),
[Input(‘my-date-picker-range’, ‘start_date’),
Input(‘my-date-picker-range’, ‘end_date’)])
def update_output(start_date, end_date):
string_prefix = ‘You have selected: ’
if start_date is not None:
start_date = dt.strptime(start_date.split(’ ‘)[0], ‘%Y-%m-%d’)
start_date_string = start_date.strftime(’%B %d, %Y’)
string_prefix = string_prefix + ‘Start Date: ’ + start_date_string + ’ | ’
if end_date is not None:
end_date = dt.strptime(end_date.split(’ ‘)[0], ‘%Y-%m-%d’)
end_date_string = end_date.strftime(’%B %d, %Y’)
string_prefix = string_prefix + 'End Date: ’ + end_date_string
if len(string_prefix) == len('You have selected: '):
return ‘Select a date to see it displayed here’
else:
return string_prefix@app.callback(
Output(‘table’, ‘columns’),
[Input(‘my-date-picker-range’, ‘start_date’),
Input(‘my-date-picker-range’, ‘end_date’)])
def update_columns(start_date, end_date):
df2 = df.loc[start_date: end_date]
columns =[{“name”: i, “id”: i} for i in df2.columns]return columns
code for the callbacks are taken from (https://dash.plot.ly/dash-core-components/datepickerrange) and qdumount’s answer here (DatePickerRange to Update Data Table - #4 by Troy). personally im not sure if the df2 above in callbacks is right.
the error in terminal is
dash.exceptions.NonExistentIdException:
Attempting to assign a callback to the
component with the id “table” but no
components with id “table” exist in the
app’s layout.Here is a list of IDs in layout:
[‘table-sorting-filtering’, ‘my-link’, ‘my-date-picker-range’, ‘output-container-date-picker-range’, ‘table-paging-with-graph-container’, ‘interval_component’]
If you are assigning callbacks to components that are generated by other callbacks (and therefore not in the initial layout), then you can suppress this exception by setting `suppress_callback_exceptions=True`.