|
# -*- coding: utf-8 -*- |
|
from time import sleep |
|
|
|
import dash |
|
from dash_core_components import Graph |
|
from dash_html_components import H1, Div, Button |
|
from comp import Button |
|
from dash.dependencies import Input, Output, Event, State |
|
|
|
app = dash.Dash() |
|
app.scripts.config.serve_locally = True |
|
|
|
|
|
app.layout = Div(children=[ |
|
H1(children='Hello Dash'), |
|
|
|
Div(children=''' |
|
Dash: A web application framework for Python. |
|
'''), |
|
|
|
Graph( |
|
id='graph', |
|
figure={ |
|
'data': [ |
|
{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'}, |
|
{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'}, |
|
], |
|
'layout': { |
|
'title': 'Dash Data Visualization' |
|
} |
|
} |
|
), |
|
Div(children=[ |
|
Button('btn1', id='btn1', title='off'), |
|
Button('btn2', id='btn2', title='off') |
|
], |
|
style={'textAlign': 'right', 'width': '90%', 'margin': 'auto 0'} |
|
) |
|
]) |
|
|
|
|
|
btns = [0] |
|
@app.callback( |
|
Output(component_id='btn1', component_property='title'), |
|
events=[Event(component_id='btn1', component_event='click')]) |
|
def bb1(): |
|
btns.append('1') |
|
return '1' |
|
|
|
@app.callback( |
|
Output(component_id='btn2', component_property='title'), |
|
events=[Event(component_id='btn2', component_event='click')]) |
|
def bb2(): |
|
btns.append('2') |
|
return '2' |
|
|
|
@app.callback( |
|
Output(component_id='graph', component_property='figure'), |
|
inputs=[Input(component_id='btn1', component_property='title'),Input(component_id='btn2', component_property='title')] |
|
) |
|
def btn12(btn1, btn2): |
|
st = btns[-1] |
|
if st == '1': |
|
return { |
|
'data': [ |
|
{'x': [1, 2, 3], 'y': [1, 2, 3], 'type': 'bar', 'name': 'SF'}, |
|
{'x': [1, 2, 3], 'y': [4, 5, 6], 'type': 'bar', 'name': u'Montréal'}, |
|
], |
|
'layout': { |
|
'title': 'Dash Data Visualization' |
|
} |
|
} |
|
return { |
|
'data': [ |
|
{'x': [1, 2, 3], 'y': [4, 5, 6], 'type': 'bar', 'name': u'Montréal'}, |
|
{'x': [1, 2, 3], 'y': [1, 2, 3], 'type': 'bar', 'name': 'SF'}, |
|
], |
|
'layout': { |
|
'title': 'Dash Data Visualization' |
|
} |
|
} |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
app.run_server(debug=True, port=7777) |
hey what is this
comp
library you are using? I don't recognize it and the only thing on Pypi is this, which does not seem to be the same.