Skip to content

Commit

Permalink
Dropdowns UI 1D+2D graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
krystophny committed Jan 14, 2020
1 parent ca1de87 commit 9043f46
Showing 1 changed file with 59 additions and 9 deletions.
68 changes: 59 additions & 9 deletions profit/ui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@
}

indata = pd.read_csv('input.txt', delim_whitespace=True, escapechar='#')
indata.rename(columns=lambda x: x.strip(), inplace=True)
outdata = pd.read_csv('output.txt', delim_whitespace=True, escapechar='#')
outdata.rename(columns=lambda x: x.strip(), inplace=True)

data = pd.concat([indata, outdata], 1)

invars = indata.keys()
dropdown_opts = [{'label': invar, 'value': invar} for invar in invars]

app.layout = html.Div(
[
html.Div(
Expand All @@ -33,9 +39,36 @@
id='tabs',
children=[
dcc.Tab(
label='Graphs',
label='1D Graphs',
selected_style=tab_selected_style,
children=[
html.Div(dcc.Dropdown(
id='invar',
options=dropdown_opts,
value=invars[0]
)),
html.Div(dcc.Graph(id='graph1'))
]
),
dcc.Tab(
label='2D Graphs',
selected_style=tab_selected_style,
children=[html.Div(dcc.Graph(id="graph1"))]
children=[
html.Div([
dcc.Dropdown(
id='invar1',
options=dropdown_opts,
value=invars[0]
),
dcc.Dropdown(
id='invar2',
options=dropdown_opts,
value=invars[1]
),
]
),
html.Div(dcc.Graph(id='graph2'))
]
),
dcc.Tab(
label='Tables',
Expand All @@ -59,15 +92,32 @@


@app.callback(
dash.dependencies.Output("graph1", "figure"),
[dash.dependencies.Input("tabs", "value")]
dash.dependencies.Output('graph1', 'figure'),
[dash.dependencies.Input('tabs', 'value'),
dash.dependencies.Input('invar', 'value'), ]
)
def update_figure(tab, invar):
if invar is None:
return go.Figure()
fig = go.Figure(data=[
go.Scatter(x=indata[invar].values,
y=outdata.values[:, 0], mode='markers')
])
return fig


@app.callback(
dash.dependencies.Output('graph2', 'figure'),
[dash.dependencies.Input('tabs', 'value'),
dash.dependencies.Input('invar1', 'value'),
dash.dependencies.Input('invar2', 'value'), ]
)
def update_figure(selected):
def update_figure2(tab, invar1, invar2):
if invar1 is None or invar2 is None:
return go.Figure()
fig = go.Figure(data=[
# go.Scatter(x=indata.values[:, 0],
# y=outdata.values[:, 0], mode='markers'),
go.Scatter3d(x=indata.values[:, 0],
y=indata.values[:, 1],
go.Scatter3d(x=indata[invar1],
y=indata[invar2],
z=outdata.values[:, 0], mode='markers')
])
return fig
Expand Down

0 comments on commit 9043f46

Please sign in to comment.