Guest User

Untitled

a guest
Feb 17th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. import dash
  2. import dash_core_components as dcc
  3. import dash_bootstrap_components as dbc
  4. import pandas as pd
  5.  
  6. def data_preprocessing():
  7. df = pd.DataFrame({'level1': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B'],'level2': ['A1', 'A1', 'A1', 'A2', 'B1', 'B2', 'B2', 'B3'],
  8. 'level3': ['A1.1', 'A1.2', 'A1.3', 'A2.1', 'B1.1', 'B2.1', 'B2.2', 'B3.1'],
  9. 'level4': ['A1.1.1', 'A1.2.1', 'A1.3.1', 'A2.1.1', 'B1.1.1', 'B2.1.1', 'B2.2.1', 'B3.1.1']})
  10. return df
  11.  
  12. def dropdown_menu_filters(position, df):
  13. types = df[position].unique()
  14. return dcc.Dropdown(id = f'dropdown-{position}',
  15. options=[{'label': type,'value': type} for type in types], value='all', multi=True)
  16.  
  17. def create_app(df):
  18. app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
  19. app.layout = dbc.Container([dbc.Row(dbc.Col(['level1']))]+[dbc.Row(dbc.Col([(dropdown_menu_filters('level1', df))]))] +
  20. [dbc.Row(dbc.Col(['level2']))]+[dbc.Row(dbc.Col([(dropdown_menu_filters('level2', df))]))] +
  21. [dbc.Row(dbc.Col(['level3']))]+[dbc.Row(dbc.Col([(dropdown_menu_filters('level3', df))]))] +
  22. [dbc.Row(dbc.Col(['level4']))]+[dbc.Row(dbc.Col([(dropdown_menu_filters('level4', df))]))])
  23. return app
  24. dataf = data_preprocessing()
  25. app = create_app(dataf)
  26. if __name__ == '__main__':
  27. app.run_server(debug=True)
Add Comment
Please, Sign In to add comment