Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Python by registered user vlad_areva ( 9 years ago )
import dash
from dash.dependencies import Output, Input
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd

df = pd.read_csv('rounded.csv')

app = dash.Dash()

OPTIONS = [{
    'label': df.iloc[i]['name'],
    'value': df.iloc[i]['name']
} for i in range(len(df))]


app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    dcc.Dropdown(
        id='my_dropdown',
        options=OPTIONS,
        value='MTL'
    ),

    dcc.Graph(id='my_bar')
])


@app.callback(Output('my_bar', 'figure'), [Input('my_dropdown', 'value')])
def update_bars(selected_value):
    filtered_df = df[df.name == selected_value]
    old_price = filtered_df.old_price.unique
    new_price = filtered_df.new_price.unique
    old_profit = filtered_df.old_profit.unique
    new_profit = filtered_df.new_profit.unique
    # print('filtered_df', filtered_df)
    # print('prices', filtered_df.old_price)
    # print('price', filtered_df.old_price.unique)
    # for i in filtered_df.old_price.unique():
    #     old_price = filtered_df[filtered_df['old_price'] == i].old_price
    # for i in filtered_df.new_price.unique():
    #     new_price = filtered_df[filtered_df['new_price'] == i]
    # for i in filtered_df.old_profit.unique():
    #     old_profit = filtered_df[filtered_df['old_profit'] == i]
    # for i in filtered_df.new_profit.unique():
    #     new_profit = filtered_df[filtered_df['new_profit'] == i]

    # print('old_price', old_price)
    # print('new_price', new_price)
    # print('old_profit', old_profit)
    # print('new_profit', new_profit)

    return {
        'data': [
            {'x':  [1], 'y': old_price, 'type': 'bar', 'name': 'old_price'},
            {'x': [2], 'y': new_price, 'type': 'bar', 'name': 'new_price'},
            {'x': [4], 'y': old_profit, 'type': 'bar', 'name': 'old_profit'},
            {'x': [5], 'y': new_profit, 'type': 'bar', 'name': 'new_profit'},
        ],
        'layout': {
            'title': 'Dash Data Visualization'
        }
    }


if __name__ == '__main__':
    app.run_server(debug=True)

 

Revise this Paste

Your Name: Code Language: