Created
October 4, 2017 22:57
-
-
Save jwhendy/2d9a355f8060a4dbac9f1020a790e57d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import datetime | |
import os | |
import math | |
import numpy as np | |
import dash | |
import dash_core_components as dcc | |
import dash_html_components as html | |
import pandas as pd | |
import plotly.graph_objs as go | |
import psutil | |
global params | |
params = {'dur': 5, 'freq': 10} | |
global data | |
# data = pd.DataFrame(columns=['i', 'num']) | |
data = pd.DataFrame({'i': pd.Series(range(20)), | |
'num': pd.Series(np.random.uniform(0, 10, 20))}) | |
def generate_inputs(params): | |
dur = [html.Label(html.Strong('duration to sample, sec')), | |
dcc.Input(type='number', value=params['dur'], id='dur')] | |
freq = [html.Label(html.Strong('sample frequency, n/sec')), | |
dcc.Input(type='number', value=params['freq'], id='freq')] | |
run_test = [html.Label(html.Strong('ready?')), | |
html.Button('run test!', id='run', n_clicks=0)] | |
input_list = [dur, freq, run_test] | |
widgets = list() | |
for sublist in input_list: | |
sublist.append(html.H1('')) | |
for item in sublist: | |
widgets.append(item) | |
return widgets | |
def build_layout(): | |
layout = html.Div([ | |
html.H2('a dashboard'), | |
html.Div(dcc.Interval(id='refresh', interval=1000)), | |
html.Div(generate_inputs(params), | |
style={'width' : '15%', 'float' : 'left' }), | |
# html.Div(generate_plot(data)) | |
html.Div(id='plot') | |
]) # app.layout | |
return layout | |
def generate_plot(data): | |
plot = dcc.Graph( | |
id='the_plot', | |
figure={ | |
'data': [go.Scatter(name='plot', | |
x=data['i'], | |
y=data['num'])], | |
'layout': go.Layout(title= 'Live test data')#, | |
}, | |
style={'width': '80%', 'float': 'right'} | |
) # dcc.Graph | |
return plot | |
app = dash.Dash() | |
app.layout = build_layout | |
app.css.append_css({"external_url": "https://codepen.io/chriddyp/pen/bWLwgP.css"}) | |
@app.callback( | |
dash.dependencies.Output('plot', 'children'), | |
events=[dash.dependencies.Event('refresh', 'interval')]) | |
def update(): | |
data.loc[len(data)] = [len(data), np.random.uniform(10)] | |
return generate_plot(data) | |
if __name__ == '__main__': | |
app.run_server(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment