Skip to content

Commit

Permalink
working addable scan table
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesC30 committed Mar 2, 2023
1 parent 07caca3 commit e975332
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 45 deletions.
18 changes: 17 additions & 1 deletion app_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
from dash import html, dcc
import dash_bootstrap_components as dbc

import plotly.graph_objects as go

from xas.tiled_io import sort_node_by_metadata_key

def build_scangroup_interactable(scangroup_node):
scan_labels = [html.Div([
html.Div(f"{v.metadata['scan_id']}",
style={"display": "inline-block", "padding": "5px"}),
style={"display": "inline-block", "padding": "5px"},),
html.Button("+",
id={"type": "plus_btn",
"scan_id": f"{v.metadata['scan_id']}",
"uid": k},
style={"background-color": "white"}),
html.Br(),
Expand Down Expand Up @@ -60,3 +63,16 @@ def build_proposal_accordion(proposal_node, sort_key):
]
return dbc.Accordion(proposal_accordion_items, start_collapsed=True, always_open=True)


visualization_tab = dbc.Tab(
[
dbc.Row(
html.Table([
html.Thead(html.Tr([html.Th("Scan"), html.Th("mut"), html.Th("muf"), html.Th("mur")])),
], style={"width": "50%"}, id="scan_table"),
justify="center"
),
dbc.Row(dcc.Graph(figure=go.Figure(layout={"height": 800}), id="spectrum_plot")),
],
label="Visualization",
)
Empty file added assets/style.css
Empty file.
84 changes: 40 additions & 44 deletions dash_app.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import dash
from dash import html, dcc, Input, Output, State, ALL
from dash import html, dcc, Input, Output, State, ALL, MATCH
import dash_bootstrap_components as dbc

import numpy as np
import plotly.express as px
import plotly.graph_objects as go

from tiled.queries import Key
from xas.tiled_io import get_iss_sandbox, filter_node_for_proposal
from xas.analysis import check_scan

from app_components import build_proposal_accordion
from app_components import build_proposal_accordion, visualization_tab

app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
app.title = "new ISS app"


app.layout = dbc.Container([
dcc.Store(id="bnl_username"),
dbc.Modal(
dbc.ModalHeader(""),
dbc.ModalBody(dbc.Input(id="username_input")),
),
html.H1("XDash",
style={
"textAlign": "center",
Expand Down Expand Up @@ -49,10 +43,13 @@
),
], width=3),
dbc.Col([
dbc.Row(dcc.Graph(figure=go.Figure(layout={"height": 800}), id="spectrum_plot")),
dbc.Row(dbc.Col(
dbc.Button("plot selected spectra", id="plot_btn", class_name="d-grid gap-2 col-3 mx-auto"),
)),
dbc.Tabs([
visualization_tab,
]),
# dbc.Row(dcc.Graph(figure=go.Figure(layout={"height": 800}), id="spectrum_plot")),
# dbc.Row(dbc.Col(
# dbc.Button("plot selected spectra", id="plot_btn", class_name="d-grid gap-2 col-3 mx-auto"),
# )),
], width=9),
]),
], fluid=True)
Expand All @@ -75,47 +72,46 @@ def show_proposal_accordion(n_search_clicks, n_sort_clicks, dropdown_choice, yea
return build_proposal_accordion(filter_node_for_proposal(ISS_SANDBOX, year, cycle, proposal), sort_key=dropdown_choice)



@app.callback(
Output("spectrum_plot", "figure"),
Input({"type": "plus_btn", "uid": ALL}, "n_clicks"),
State("spectrum_plot", "figure"),
Output("scan_table", "children"),
Input({"type": "plus_btn", "scan_id": ALL, "uid": ALL}, "n_clicks"),
State("scan_table", "children"),
State({"type": "table_row", "uid": ALL}, "id"),
prevent_initial_call=True,
)
def add_spectrum_to_plot(click, current_fig):
def add_scan_to_table(click, table_rows, row_id_dicts):
# print(dash.ctx.triggered_id)
uid = dash.ctx.triggered_id["uid"]
print(dash.ctx.triggered_id)
fig = go.Figure(current_fig)

df = ISS_SANDBOX[uid].read()
df["mut"] = -np.log(df["it"] / df["i0"])
df["mur"] = -np.log(df["ir"] / df["it"])
df["muf"] = df["iff"] / df["i0"]

for mu in ("mut", "muf", "mur"):
fig.add_scatter(x=df["energy"], y=df[mu])

return fig
scan_id = dash.ctx.triggered_id["scan_id"]
new_row = html.Tr([html.Td(scan_id),
html.Td(html.Div(dbc.Checkbox(value=True, id={"type": "mut_check", "uid": uid}))),
html.Td(html.Div(dbc.Checkbox(value=True, id={"type": "muf_check", "uid": uid}))),
html.Td(html.Div(dbc.Checkbox(value=True, id={"type": "mur_check", "uid": uid}))),
], id={"type": "table_row", "uid": uid})
if uid not in [d["uid"] for d in row_id_dicts]:
table_rows.append(new_row)
return table_rows


# @app.callback(
# Output("spectrum_plot", "figure"),
# Input("plot_btn", "n_clicks"),
# State({"type": "scan_checklist", "uid": ALL}, "value"),
# State({"type": "scan_checklist", "uid": ALL}, "id"),
# Input({"type": "plus_btn", "uid": ALL}, "n_clicks"),
# State("spectrum_plot", "figure"),
# prevent_initial_call=True,
# )
# def plot_selected_spectra(click, checklist_values, checklist_id_dicts):
# fig = go.Figure(layout={"height": 800})
# for cv, cd in zip(checklist_values, checklist_id_dicts):
# if cv is None:
# continue
# uid = cd["uid"]
# df = ISS_SANDBOX[uid].read()
# df["mut"] = -np.log(df["it"] / df["i0"])
# df["mur"] = -np.log(df["ir"] / df["it"])
# df["muf"] = df["iff"] / df["i0"]
# for val in cv:
# fig.add_scatter(x=df["energy"], y=df[val])
# def add_spectrum_to_plot(click, current_fig):
# uid = dash.ctx.triggered_id["uid"]
# print(dash.ctx.triggered_id)
# fig = go.Figure(current_fig)

# df = ISS_SANDBOX[uid].read()
# df["mut"] = -np.log(df["it"] / df["i0"])
# df["mur"] = -np.log(df["ir"] / df["it"])
# df["muf"] = df["iff"] / df["i0"]

# for mu in ("mut", "muf", "mur"):
# fig.add_scatter(x=df["energy"], y=df[mu])

# return fig


Expand Down

0 comments on commit e975332

Please sign in to comment.