# How to return a datatable updated by 2 dropdowns as inputs in Plotly Python

**URL:** <https://community.plotly.com/t/how-to-return-a-datatable-updated-by-2-dropdowns-as-inputs-in-plotly-python/35887>\
**Category:** Dash Python\
**Created:** [March 6, 2020, 3:00am UTC](https://community.plotly.com/t/how-to-return-a-datatable-updated-by-2-dropdowns-as-inputs-in-plotly-python/35887 "2020-03-06T03:00:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yts61](https://avatars.discourse-cdn.com/v4/letter/y/b77776/32.png) [@yts61](https://community.plotly.com/u/yts61)\
**Post date:** [March 6, 2020, 3:00am UTC](https://community.plotly.com/t/how-to-return-a-datatable-updated-by-2-dropdowns-as-inputs-in-plotly-python/35887/1 "2020-03-06T03:00:36Z")

</div>

As titled, i am creating a plotly dashboard with a data-table only. There will be 2 drop-downs as inputs, and the data-table will update according to the drown-downs. How do I set the layout and callbacks?

```
import pandas as pd
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_table as dt
from dash.dependencies import Input, Output, State

df = pd.read_csv(https://elartedm.com/wp-content/uploads/2020/03/data_hk.csv, header=0, encoding = 'utf8')

app = dash.Dash()
application = app.server

dropdown = html.Div([html.Label('district'),
             dcc.Dropdown(id='dropdown_d',
                          options=[{'label': i, 'value': i} for i in df["district"].unique()], value='中西區 Central &'),
             html.Label('address'),
             dcc.Dropdown(id='dropdown_a',
                          options=[{'label': i, 'value': i} for i in df["address"].unique()], value='第二街143號海昇大廈2座')])

final_table = html.Div([dash_table.DataTable(id="final_table")])

app.layout = html.Div([dropdown, final_table])

@app.callback(Output('final_table', 'data'),
          [Input('dropdown_d', 'value'),
           ])

def update_table(selected_value):
    df = pd.read_csv(https://elartedm.com/wp-content/uploads/2020/03/data_hk.csv, header=0, encoding = 'utf8')
    df_updated = df[df["district"] == selected_value]
    columns = [{'name': i, 'id': i} for i in df_updated.columns]
    data = df.to_dict('records')
    return columns, data

if __name__ == " __main__":
    app.run_server(debug=True, port=8055)

```

This is the farthest i can get. The code above is only trying to update the data-table from 1 dropdown value, but my goal is to update by 2 dropdown values.

any help is very much appreciated.  
in case the data file is needed, here is the link to the [data](https://elartedm.com/wp-content/uploads/2020/03/data_hk.csv).

---

<div class="post-metadata">

**Author:** ![flyingcujo](https://avatars.discourse-cdn.com/v4/letter/f/e480ec/32.png) [@flyingcujo](https://community.plotly.com/u/flyingcujo)\
**Post date:** [March 6, 2020, 12:12pm UTC](https://community.plotly.com/t/how-to-return-a-datatable-updated-by-2-dropdowns-as-inputs-in-plotly-python/35887/2 "2020-03-06T12:12:04Z")

</div>

Add your other dropdown to the `Input` as shown below. Also note you need to pass in another arg to your update\_table.

```python
@app.callback(Output('final_table', 'data'),
          [Input('dropdown_d', 'value'),
           Input('dropdown_a', 'value'])
def update_table( selected_value, val_for_dropdown_a):

```

---

<div class="post-metadata">

**Author:** ![SandK](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@SandK](https://community.plotly.com/u/SandK)\
**Post date:** [March 6, 2020, 1:03pm UTC](https://community.plotly.com/t/how-to-return-a-datatable-updated-by-2-dropdowns-as-inputs-in-plotly-python/35887/3 "2020-03-06T13:03:36Z")

</div>

You can `Input` both dropdown value, and pass both arg to update\_table.

```auto
@app.callback(
    Output('final_table', 'data'),
    [Input('dropdown_d', 'value'),
     Input('dropdown_a', 'value'),]
)
def update_table(dropdown_d, dropdown_a):
    ... other code...

```

---

<div class="post-metadata">

**Author:** ![yts61](https://avatars.discourse-cdn.com/v4/letter/y/b77776/32.png) [@yts61](https://community.plotly.com/u/yts61)\
**Post date:** [March 6, 2020, 2:06pm UTC](https://community.plotly.com/t/how-to-return-a-datatable-updated-by-2-dropdowns-as-inputs-in-plotly-python/35887/4 "2020-03-06T14:06:48Z")

</div>

> [@SandK](#):
>
> @app.callback( Output(‘final\_table’, ‘data’)

Thank you guys for the answers, I will try it out when I m with my mac.

But allow me one more question before that, is  
Output(‘final\_table’, ‘data’) correct? Because the entire piece of code wasn’t working, and I saw some may use Output(‘final\_table’, ‘children’) here.

---

<div class="post-metadata">

**Author:** ![flyingcujo](https://avatars.discourse-cdn.com/v4/letter/f/e480ec/32.png) [@flyingcujo](https://community.plotly.com/u/flyingcujo)\
**Post date:** [March 6, 2020, 2:19pm UTC](https://community.plotly.com/t/how-to-return-a-datatable-updated-by-2-dropdowns-as-inputs-in-plotly-python/35887/5 "2020-03-06T14:19:34Z")

</div>

Since your function as writen is returning `data` and `columns`, your `Output` should be:

```python
@app.callback(
  [Output('final_table', 'data'),
  Output('final_table', 'columns')],   
  [Input('dropdown_d', 'value'),
  Input('dropdown_a', 'value'])
def update_table( selected_value, val_for_dropdown_a):
  ... your code...
  return data, columns

```

But if your columns are not changing, you can just return the `data`. It all depends on what you want/need to update.

---

<div class="post-metadata">

**Author:** ![yts61](https://avatars.discourse-cdn.com/v4/letter/y/b77776/32.png) [@yts61](https://community.plotly.com/u/yts61)\
**Post date:** [March 7, 2020, 1:19pm UTC](https://community.plotly.com/t/how-to-return-a-datatable-updated-by-2-dropdowns-as-inputs-in-plotly-python/35887/6 "2020-03-07T13:19:37Z")

</div>

yes, it solved my problem, thank you all!
