I have a large dataframe that I’ve turned into a data table that can be used with callbacks. I then made drop down boxes with filtering options and I made a callback that would filter based on the drop down boxes, the code is below :
app.layout = html.Div([
html.Div(className='Filters', children=[
dcc.Tabs(id='filters', children=[
dcc.Tab(label='Control Panel', children=[
dcc.Dropdown(
id='FromJobdropdown',
clearable = False,
options = [{'label': i, 'value': i} for i in data['fromJobtitle'].unique()],
placeholder = 'Choose a sender job title'
),
dcc.Dropdown(
id='toJobdropdown',
clearable = False,
options = [{'label': i, 'value': i} for i in data['toJobtitle'].unique()],
placeholder = 'Choose a recipient job title'
),
dcc.DatePickerRange(
id='date-picker-range',
min_date_allowed=date(1998, 11, 12),
max_date_allowed=date(2002, 6, 20),
initial_visible_month=date(1998, 11, 12),
end_date=date(2002, 6, 20)
),
dash_table.DataTable(
id='table',
columns=[{"name": i, "id": i} for i in data.columns],
data=data.to_dict('record'),
editable = True,
)
]),
]),
])
])
@app.callback(
Output('table', 'data'),
[Input('FromJobDropdown','value'),
Input('ToJobDropdown','value'),
Input('date-picker-range','start_date'),
Input('date-picker-range','end_date')]
)
def update_table(FromJob,ToJob,start_time,end_time):
filtration= ( (data['fromJobtitle'] == FromJob) &
(data['toJobtitle'] == ToJob) &
(data['date'] >= start_time) &
(data['date']<= end_time))
filtered_df = data[filtration]
return filtered_df.to_dict('record')
It should be updating the data table the moment you change a single parameter in the drop down box but mine just stays static. Even going to the next page does nothing. Can I please get some help with what may be going on?