|
12 | 12 | from django_plotly_dash import DjangoDash |
13 | 13 |
|
14 | 14 | #from .urls import app_name |
15 | | -app_name ="DPD demo application" |
| 15 | +app_name = "DPD demo application" |
16 | 16 |
|
17 | 17 | dashboard_name1 = 'dash_example_1' |
18 | 18 | dash_example1 = DjangoDash(name=dashboard_name1, |
19 | | - serve_locally=True, |
20 | | - app_name=app_name |
21 | | - ) |
| 19 | + serve_locally=True, |
| 20 | + app_name=app_name |
| 21 | + ) |
22 | 22 |
|
23 | 23 | # Below is a random Dash app. |
24 | 24 | # I encountered no major problems in using Dash this way. I did encounter problems but it was because |
25 | 25 | # I was using e.g. Bootstrap inconsistenyly across the dash layout. Staying consistent worked fine for me. |
26 | 26 | dash_example1.layout = html.Div(id='main', |
27 | | - children=[ |
28 | | - |
29 | | - html.Div([ |
30 | | - dcc.Dropdown( |
31 | | - id='my-dropdown1', |
32 | | - options=[ |
33 | | - {'label': 'New York City', 'value': 'NYC'}, |
34 | | - {'label': 'Montreal', 'value': 'MTL'}, |
35 | | - {'label': 'San Francisco', 'value': 'SF'} |
36 | | - ], |
37 | | - value='NYC', |
38 | | - className='col-md-12', |
39 | | - |
40 | | - ), |
41 | | - html.Div(id='test-output-div') |
42 | | - ]), |
| 27 | + children=[ |
| 28 | + html.Div([dcc.Dropdown(id='my-dropdown1', |
| 29 | + options=[{'label': 'New York City', 'value': 'NYC'}, |
| 30 | + {'label': 'Montreal', 'value': 'MTL'}, |
| 31 | + {'label': 'San Francisco', 'value': 'SF'} |
| 32 | + ], |
| 33 | + value='NYC', |
| 34 | + className='col-md-12', |
| 35 | + ), |
| 36 | + html.Div(id='test-output-div') |
| 37 | + ]), |
43 | 38 |
|
44 | 39 | dcc.Dropdown( |
45 | 40 | id='my-dropdown2', |
|
59 | 54 | @dash_example1.expanded_callback( |
60 | 55 | dash.dependencies.Output('test-output-div', 'children'), |
61 | 56 | [dash.dependencies.Input('my-dropdown1', 'value')]) |
62 | | -def callback_test(*args, **kwargs): |
| 57 | +def callback_test(*args, **kwargs): #pylint: disable=unused-argument |
| 58 | + 'Callback to generate test data on each change of the dropdown' |
63 | 59 |
|
64 | 60 | # Creating a random Graph from a Plotly example: |
65 | 61 | N = 500 |
66 | 62 | random_x = np.linspace(0, 1, N) |
67 | 63 | random_y = np.random.randn(N) |
68 | 64 |
|
69 | 65 | # Create a trace |
70 | | - trace = go.Scatter( |
71 | | - x = random_x, |
72 | | - y = random_y |
73 | | - ) |
| 66 | + trace = go.Scatter(x=random_x, |
| 67 | + y=random_y) |
74 | 68 |
|
75 | 69 | data = [trace] |
76 | 70 |
|
77 | 71 | layout = dict(title='', |
78 | | - yaxis = dict(zeroline = False, title='Total Expense (£)',), |
79 | | - xaxis = dict(zeroline = False, title='Date', tickangle=0), |
80 | | - margin=dict(t=20, b=50, l=50, r=40), |
81 | | - height=350, |
82 | | - ) |
| 72 | + yaxis=dict(zeroline=False, title='Total Expense (£)',), |
| 73 | + xaxis=dict(zeroline=False, title='Date', tickangle=0), |
| 74 | + margin=dict(t=20, b=50, l=50, r=40), |
| 75 | + height=350, |
| 76 | + ) |
83 | 77 |
|
84 | 78 |
|
85 | 79 | fig = dict(data=data, layout=layout) |
86 | 80 | line_graph = dcc.Graph(id='line-area-graph2', figure=fig, style={'display':'inline-block', 'width':'100%', |
87 | | - 'height': '100%;'} ) |
| 81 | + 'height':'100%;'} ) |
88 | 82 | children = [line_graph] |
89 | 83 |
|
90 | 84 | return children |
|
0 commit comments