Created
November 1, 2017 20:20
-
-
Save sametz/9cb409776c0a98afd43262b980edfb9e to your computer and use it in GitHub Desktop.
Hacking a web app version of pydnmr, using plot.ly's Dash.
This file contains hidden or 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
import dash | |
import dash_core_components as dcc | |
import dash_html_components as html | |
import plotly.graph_objs as go | |
import numpy as np | |
from testdata import TWOSPIN_SLOW | |
entry_names = ['va', 'vb', 'ka','wa', 'wb', 'pa'] | |
entry_dict = {'va': 165, | |
'vb': 135, | |
'ka': 1.5, | |
'wa': 0.5, | |
'wb': 0.5, | |
'pa': 50} | |
app = dash.Dash() | |
app.css.append_css( | |
{'external_url': 'https://codepen.io/chriddyp/pen/bWLwgP.css'}) | |
inputs = [ | |
dcc.Input( | |
type='number', | |
value=entry_dict[key]) | |
for key in entry_names] | |
test_inputs = [ | |
dcc.Input( | |
type='number', | |
value=entry_dict[entry_names[0]]), | |
dcc.Input( | |
type='number', | |
value=entry_dict[entry_names[1]])] | |
app.layout = html.Div([ | |
# html.Div([ | |
# dcc.Input( | |
# type='number', | |
# value=entry_dict[entry_names[0]]), | |
# | |
# dcc.Input( | |
# type='number', | |
# value=entry_dict[entry_names[1]])] | |
# ), | |
# | |
# html.Div( | |
# [html.Label(key) for key in entry_names] | |
# ), | |
# | |
# html.Div([ | |
# # html.Label(key), | |
# dcc.Input( | |
# type='number', | |
# name=key, | |
# value=entry_dict[key]) | |
# for key in entry_names], | |
# style={'display': 'inline-block'} | |
# ), | |
html.Div([ | |
html.Div([ | |
html.Label(key), | |
dcc.Input( | |
type='number', | |
name=key, | |
value=entry_dict[key])], | |
style={'display': 'inline-block', 'textAlign': 'center'}) | |
for key in entry_names]#, | |
# style={'display': 'inline-block'} | |
), | |
dcc.Graph( | |
id='test-dnmr-plot', | |
figure={ | |
# IMPORTANT: despite what some online examples show, apparently | |
# 'data' must be a list, even if only one element. Otherwise, if [] | |
# omitted, it won't plot. | |
'data': [go.Scatter( | |
x=TWOSPIN_SLOW[0], | |
y=TWOSPIN_SLOW[1], | |
text='banana', | |
mode='lines', | |
opacity=0.7, | |
line={ | |
'color': 'blue', | |
'width': 1 | |
}, | |
marker={ | |
'size': 15, | |
'line': {'width': 0.5, 'color': 'white'} | |
}, | |
name='test' | |
)], | |
'layout': go.Layout( | |
xaxis={'title': 'frequency', | |
'autorange': 'reversed'}, | |
yaxis={'title': 'intensity'}, | |
margin={'l': 40, 'b': 40, 't': 10, 'r': 10}, | |
legend={'x': 0, 'y': 1}, | |
hovermode='closest') | |
# 'data': [{ | |
# 'x': TWOSPIN_SLOW[0], | |
# 'y': TWOSPIN_SLOW[1] | |
# }], | |
# 'layout': {'margin': {'l': 40, 'r': 0, 't': 20, 'b': 30}} | |
} | |
) | |
]) | |
if __name__ == '__main__': | |
# print(list(zip(TWOSPIN_SLOW[0][:10], TWOSPIN_SLOW[1][:10]))) | |
# x = [i for i in TWOSPIN_SLOW[0]] | |
# y = [j for j in TWOSPIN_SLOW[1]] | |
# print(list(zip(x[:10], y[:10]))) | |
# print(list(zip(random_x, random_y))[:10]) | |
app.run_server() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment