Hello everyone,
First of all, I am not good at English. I’m sorry.
I’m a beginner who just started dash.I need your help.
Here’s what I’m trying to do:
I want to create a table by reading csv with two or more filter information.
Step.
- Set filter.(multiple)
- Set additional filters.(multiple)
- Send filter information to submit button and read csv again.
I’d really appreciate it if you could tell me how to do it.
ex)
df = pd.read_csv(‘data.csv’,encoding = “utf-8”)
app = dash.Dash()
app.layout = html.Div(
children=[
html.H4(children=‘my table’),
dcc.Dropdown(id=‘dropdown1’, options=
[{‘label’: i, ‘value’: i} for i in df.project_name.unique()], placeholder=‘project_name’),
dcc.Dropdown(id=‘dropdown2’, options=
[{‘label’: i, ‘value’: i} for i in df.client.unique()], placeholder=‘client’),
html.Div(id=‘table-container’)
])
app.css.append_css({“external_url”: “https://codepen.io/chriddyp/pen/bWLwgP.css”})
@app.callback(
Output(‘table-container’, ‘children’),
[
Input(‘dropdown1’, ‘value’),
Input(‘dropdown2’, ‘value’)
])
def display_table(d1,d2):
if d1 is None:
return generate_table(df)
dff1 = df[df.project_name.str.contains(d1)]
dff2 = df[df.client.str.contains(d2)]
frames = [dff1,dff2]
return generate_table(pd.concat(frames))
def generate_table(dataframe, max_rows=10):
return html.Table(
# Header
[html.Tr([html.Th(col) for col in dataframe.columns])] +
# Body
[html.Tr([
html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
]) for i in range(min(len(dataframe), max_rows))]
)
if name == ‘main’:
app.run_server(debug=True)