Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tab-text content #25

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 89 additions & 78 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import logging


# Bar Chart options
bar_chart_options = {'None':'None', 'MCC':'mcc', 'Site':'site','Visit':'ses','Scan':'scan'}

Expand Down Expand Up @@ -81,34 +82,6 @@
app.logger.handlers = gunicorn_logger.handlers
app.logger.setLevel(logging.INFO)

# ----------------------------------------------------------------------------
# DASH HTML COMPONENTS
# ----------------------------------------------------------------------------

offcanvas_content = html.Div([
html.Div([
html.P([' '], style={'background-color':'ForestGreen', 'height': '20px', 'width':'20px','float':'left'}),
html.P(['no known issues'], style={'padding-left': '30px', 'margin': '0px'})
]),
html.Div([
html.P([' '], style={'background-color':'Gold', 'height': '20px', 'width':'20px','float':'left', 'clear':'both'}),
html.P(['minor variations/issues; correctable'], style={'padding-left': '30px', 'margin': '0px'})
]),
html.Div([
html.P([' '], style={'background-color':'FireBrick', 'height': '20px', 'width':'20px','float':'left', 'clear':'both'}),
html.P(['significant variations/issues; not expected to be comparable'], style={'padding-left': '30px', 'margin': '0px'})
]),
])

offcanvas = html.Div([
dbc.Button("Legend", id="open-offcanvas", n_clicks=0),
dbc.Offcanvas(
offcanvas_content,
id="offcanvas",
title="Title",
is_open=False,
),
])

# ----------------------------------------------------------------------------
# DASH APP COMPONENT FUNCTIONS
Expand Down Expand Up @@ -271,6 +244,24 @@ def build_boxplot(df):
# ----------------------------------------------------------------------------
# DASH APP LAYOUT FUNCTION
# ----------------------------------------------------------------------------
def load_tab_text():
"""
Load content to display in the markdown component of the tabs from the 'tab_text' file in the github repo.
If this isn't accessible, load from a local file.
"""
try:
# try to load from github url
tab_text_url = "https://raw.githubusercontent.com/TACC/a2cps-datastore-imaging/latest/src/assets/tab_text.json"
resp = requests.get(tab_text_url)
tab_text = json.loads(resp.text)
except:
# load from local json file if github url fails
tab_text_path = "assets/tab_text.json"
with open(tab_text_path) as f:
tab_text = json.load(f)
print(tab_text)
return tab_text

def load_data_source(url_data_path, local_data_path, source):
imaging, imaging_source = load_imaging(url_data_path, local_data_path, source)
qc, qc_source = load_qc(url_data_path, local_data_path, source)
Expand Down Expand Up @@ -385,10 +376,12 @@ def serve_raw_data_store(url_data_path, local_data_path, source):
return raw_data_dictionary

def create_data_stores(source, raw_data_dictionary):
tab_text = load_tab_text()
sites = raw_data_dictionary['sites']
data_date = raw_data_dictionary['date']
data_stores = html.Div([
dcc.Store(id='session_data', data = raw_data_dictionary), #storage_type='session',
dcc.Store(id='tab_text', data=tab_text),
dcc.Store(id='report_data'),
dcc.Store(id='filtered_data'),
# html.P('Imaging Source: ' + data_dictionary['imaging_source']),
Expand Down Expand Up @@ -555,57 +548,64 @@ def see_filtering(filtered_data):

@app.callback(Output("tab-content", "children"),
Output('dropdown-sites-col','style'),
Input("tabs", "active_tab"))
def switch_tab(at):
Input("tabs", "active_tab"),
State("tab_text","data")
)
def switch_tab(at, tab_text):
if at == "tab-overview":
overview = dcc.Loading(
id="loading-overview",
children=[
html.Div([
dbc.Row([
dbc.Col([
html.H3('Scan sessions for pre-surgery (V1) and 3 month post surgery (V3) visits'),
html.Div(id='overview_div')
])
]),
dbc.Row([
dbc.Col([html.H3('Quality ratings for individual scans (up to six scans per session: T1, DWI, REST1, CUFF1, CUFF2, REST2)')]),
]),
dbc.Row([
dbc.Col([
html.Div(id='graph_stackedbar_div')
], width=10),
dbc.Col([
html.H3('Bar Chart Settings'),
html.Label('Chart Type'),
daq.ToggleSwitch(
id='toggle_stackedbar',
label=['Count','Stacked Percent'],
value=False
),
html.Label('Separate by Visit'),
daq.ToggleSwitch(
id='toggle_visit',
label=['Combined','Split'],
value=False
),

html.Label('Chart Selection'),
dcc.Dropdown(
id='dropdown-bar',
options=[
{'label': ' Site and MCC', 'value': 1},
{'label': ' Site', 'value': 2},
{'label': ' MCC', 'value': 3},
{'label': ' Combined', 'value': 4},
],
multi=False,
clearable=False,
value=1
),
],width=2),
]),
])
dbc.Row([
dbc.Col([
dcc.Markdown(tab_text['overview']['text'])
])
]),
dbc.Row([
dbc.Col([
html.H3('Scan sessions for pre-surgery (V1) and 3 month post surgery (V3) visits'),
html.Div(id='overview_div')
])
]),
dbc.Row([
dbc.Col([html.H3('Quality ratings for individual scans (up to six scans per session: T1, DWI, REST1, CUFF1, CUFF2, REST2)')]),
]),
dbc.Row([
dbc.Col([
html.Div(id='graph_stackedbar_div')
], width=10),
dbc.Col([
html.H3('Bar Chart Settings'),
html.Label('Chart Type'),
daq.ToggleSwitch(
id='toggle_stackedbar',
label=['Count','Stacked Percent'],
value=False
),
html.Label('Separate by Visit'),
daq.ToggleSwitch(
id='toggle_visit',
label=['Combined','Split'],
value=False
),

html.Label('Chart Selection'),
dcc.Dropdown(
id='dropdown-bar',
options=[
{'label': ' Site and MCC', 'value': 1},
{'label': ' Site', 'value': 2},
{'label': ' MCC', 'value': 3},
{'label': ' Combined', 'value': 4},
],
multi=False,
clearable=False,
value=1
),
],width=2),
]),
])
],
type="circle",
)
Expand All @@ -616,10 +616,16 @@ def switch_tab(at):
id="loading-discrepancies",
children=[
html.Div([
dbc.Row([
dbc.Col([html.Div(id='discrepancies_section')])
]),
])
dbc.Row([
dbc.Col([
dcc.Markdown(tab_text['discrepancies']['text'])
])
]),

dbc.Row([
dbc.Col([html.Div(id='discrepancies_section')])
]),
])
],
type="circle",
)
Expand All @@ -629,6 +635,7 @@ def switch_tab(at):
id="loading-completions",
children=[
html.Div([
html.Div( dcc.Markdown(tab_text['completions']['text'])),
html.Div(id='completions_section')
])
],
Expand All @@ -639,6 +646,7 @@ def switch_tab(at):
pies = dcc.Loading(
id="loading-pie",
children=[
html.Div( dcc.Markdown(tab_text['pie']['text'])),
html.Div(id='pie_charts')
],
type="circle",
Expand All @@ -651,6 +659,8 @@ def switch_tab(at):
cuff = dcc.Loading(
id="loading-heatmap",
children=[

html.Div( dcc.Markdown(tab_text['cuff']['text'])),
html.Div([
dbc.Row([
dbc.Col([html.Div(id='cuff_section')])
Expand Down Expand Up @@ -867,6 +877,7 @@ def update_heatmap(sites, data):
if not df.empty:
fig_heatmap = generate_heat_matrix(df.T, color_mapping_list) # transpose df to generate horizontal graph
heatmap = html.Div([
html.Div( dcc.Markdown(tab_text['heatmap']['text'])),
dcc.Graph(id='graph_heatmap', figure=fig_heatmap)
])
else:
Expand Down
1 change: 1 addition & 0 deletions src/assets/tab_text.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
"text": "This panel shows the individually determined inflatable cuff pressure used in each Cuff1 fMRI scan.\n Note that Cuff2 uses a standard pressure level (120 mmHg)."
}
}

3 changes: 3 additions & 0 deletions src/assets/testmd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Test Md File

lets see what happens when I try to load this
6 changes: 6 additions & 0 deletions src/tab_contents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from dash import dcc

testmd = dcc.Markdown('''
This is a test markdown
''')