thecoda

plotlydash

Dec 14th, 2019
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. df = pd.read_csv('data-csv')
  2. columns_df = df.columns
  3.  
  4. cols = [{'value': c, 'label': c} for c in columns_df]
  5.  
  6. app = dash.Dash()
  7.  
  8.  
  9. app.layout = html.Div([
  10.     html.Div([
  11.     dcc.Dropdown(
  12.     id='column1',
  13.     options = cols,
  14.     value = '')
  15. ], style={'width': '48%', 'display': 'inline-block'}),
  16.     html.Div([
  17.         dcc.Dropdown(id = 'column2',
  18.                      options = cols,
  19.                      value = '')
  20.     ], style={'width': '48%','float': 'right', 'display': 'inline-block'}),
  21.     html.Div([
  22.         dcc.Graph(id='scatter_graph')
  23.     ])
  24.     ])
  25.  
  26. @app.callback(
  27.     Output('plot_graph', 'figure'),
  28.     [Input('column1', 'value'),
  29.      Input('column2', 'value')])
  30. def update_graph(value):
  31.     data_plot = []
  32.     trace1 =  go.Scatter(x = df[value], y =  df[value])
  33.     data_plot.apppend(trace1)
  34.  
  35.     figure = {
  36.         'data': data_plot,
  37.         'layout': {
  38.                 'title': 'Scatter Graph' }
  39.     }
  40.     return ([figure])
  41. if __name__=='__main__':
  42.     app.run_server(debug=True)
Add Comment
Please, Sign In to add comment