@yts61 wrote:
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.
Posts: 3
Participants: 3