Hello
I ask for help with filtering the table, at the moment using the following code:
def generate_tb(dataframe):
return html.Div([
dash_table.DataTable(
id='table',
columns=[{"name": i, "id": i} for i in dataframe.columns],
data=dataframe.to_dict('records'),
style_cell={'padding': '5px',
'backgroundColor': 'rgb(238, 238, 238)',
'textAlign': 'center'},
style_header={
'backgroundColor': 'rgb(238,238,238)',
'fontWeight': 'bold'
},
page_size=20
)
])
@app.callback(
dash.dependencies.Output('table_of_choice', 'children'),
dash.dependencies.Input('dropdown', 'value'),
dash.dependencies.Input('dropdown1', 'value'),
dash.dependencies.Input('dropdown2', 'value'))
def display_table(dropdown_value, dropdown_value1, dropdown_value2):
if dropdown_value2 is not None:
dff = df.loc[df.choice.astype(str).str.contains('|'.join(str(v) for v in dropdown_value2))]
return generate_tb(dff)
if dropdown_value is None and dropdown_value1 is None and dropdown_value2 is None:
return generate_tb(df)
if dropdown_value is not None and dropdown_value1 is not None:
dff = df.loc[(df.country.astype(str).str.contains('|'.join(str(v) for v in dropdown_value))) &
(df['product'].astype(str).str.contains('|'.join(str(v) for v in dropdown_value1)))]
return generate_tb(dff)
if dropdown_value is not None and dropdown_value1 is not None and dropdown_value2 is not None:
dff = df.loc[(df.country.astype(str).str.contains('|'.join(str(v) for v in dropdown_value))) &
(df['product'].astype(str).str.contains('|'.join(str(v) for v in dropdown_value1))) &
(df.choice.astype(str).str.contains('|'.join(str(v) for v in dropdown_value2)))]
return generate_tb(dff)
if dropdown_value is not None:
dff = df.loc[df.country.astype(str).str.contains('|'.join(str(v) for v in dropdown_value))]
return generate_tb(dff)
if dropdown_value1 is not None:
dff = df.loc[df['product'].astype(str).str.contains('|'.join(str(v) for v in dropdown_value1))]
return generate_tb(dff)
when I connect filtering for 3 'dropdown_value2'
columns it does not work properly,
when filtering only by ‘dropdown_value, dropdown_value1’ it working ok,
help me how I can solve this issue for multi-filtering by 3 columns
Thank you