-
Notifications
You must be signed in to change notification settings - Fork 2
add genomics filter #23
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
Merged
Merged
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
4b2ab88
update nplinker version
gcroci2 1f620f8
move callbacks to file
gcroci2 3771cd5
fix tests
gcroci2 8b90bfe
move layouts to specific file
gcroci2 b3088bb
remove unused init and comment
gcroci2 586205d
improve layout structure by removing the functions
gcroci2 ccf44c4
fix linting error
gcroci2 cbd1ab6
fix mypy issues
gcroci2 f344618
add gcfs filters to gm tab
gcroci2 7683c3a
add collapse functionality
gcroci2 67d8355
add tests for gm_filter
gcroci2 ef02754
use accordion instead of button
gcroci2 95d4457
use dmc grid for filter
gcroci2 76842a3
add the add filter functionality
gcroci2 1ef908d
start with one filter block and keep button only on the last ones
gcroci2 17b79ac
improve ids name, add default filter value, improve gcf ids hint
gcroci2 d0d3bef
use unique id for the first block
gcroci2 d87c0f7
keep previous dropdown and input text values when a new block is added
gcroci2 34fb975
change bigscape class to multivalue bgc class
gcroci2 5bcabfe
update tests
gcroci2 56d32a4
order BGC classes and add config
gcroci2 0e232f4
handle fake file upload
gcroci2 981817d
add type hints and doc stringas
gcroci2 c11da79
fix mypy error
gcroci2 18ebd60
fix tests
gcroci2 21173ac
fix import error
gcroci2 573ef52
add last suggestions
gcroci2 a77bea2
remove gm_text_input_ids_placeholder var
gcroci2 0644ed1
remove sys.path.append
gcroci2 d811c0d
fix tests
gcroci2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,191 +1,13 @@ | ||
import os | ||
import pickle | ||
import tempfile | ||
import uuid | ||
import dash_bootstrap_components as dbc | ||
import dash_uploader as du | ||
from dash import Dash | ||
from dash import Input | ||
from dash import Output | ||
from dash import clientside_callback | ||
from dash import dcc | ||
from dash import html | ||
import sys | ||
from callbacks import app | ||
from layouts import create_layout | ||
|
||
|
||
dbc_css = "https://cdn.jsdelivr.net/gh/AnnMarieW/dash-bootstrap-templates/dbc.min.css" | ||
app = Dash(__name__, external_stylesheets=[dbc.themes.UNITED, dbc_css, dbc.icons.FONT_AWESOME]) | ||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
|
||
# ------------------ Nav Bar ------------------ # | ||
color_mode_switch = html.Span( | ||
[ | ||
dbc.Label(className="fa fa-moon", html_for="color-mode-switch"), | ||
dbc.Switch( | ||
id="color-mode-switch", | ||
value=False, | ||
className="d-inline-block ms-1", | ||
persistence=True, | ||
), | ||
dbc.Label(className="fa fa-sun", html_for="color-mode-switch"), | ||
], | ||
className="p-2", | ||
) | ||
|
||
# Define the navigation bar | ||
navbar = dbc.Row( | ||
dbc.Col( | ||
dbc.NavbarSimple( | ||
children=[ | ||
dbc.NavItem(dbc.NavLink("Doc", href="https://nplinker.github.io/nplinker/latest/")), | ||
dbc.NavItem( | ||
dbc.NavLink("About", href="https://github.com/NPLinker/nplinker-webapp"), | ||
), | ||
dbc.NavItem( | ||
color_mode_switch, | ||
className="mt-1 p-1", | ||
), | ||
], | ||
brand="NPLinker Webapp", | ||
color="primary", | ||
className="p-3 mb-2", | ||
dark=True, | ||
), | ||
), | ||
) | ||
|
||
# ------------------ Uploader ------------------ # | ||
# Configure the upload folder | ||
TEMP_DIR = tempfile.mkdtemp() | ||
du.configure_upload(app, TEMP_DIR) | ||
|
||
uploader = html.Div( | ||
[ | ||
dbc.Row( | ||
dbc.Col( | ||
du.Upload( | ||
id="dash-uploader", | ||
text="Import Data", | ||
text_completed="Uploaded: ", | ||
filetypes=["pkl", "pickle"], | ||
upload_id=uuid.uuid1(), # Unique session id | ||
cancel_button=True, | ||
max_files=1, | ||
), | ||
) | ||
), | ||
dbc.Row( | ||
dbc.Col( | ||
html.Div(children="No file uploaded", id="dash-uploader-output", className="p-4"), | ||
className="d-flex justify-content-center", | ||
) | ||
), | ||
dcc.Store(id="file-store"), # Store to keep the file contents | ||
], | ||
className="p-5 ml-5 mr-5", | ||
) | ||
|
||
# ------------------ Tabs ------------------ # | ||
# gm tab content | ||
gm_content = dbc.Row( | ||
dbc.Col( | ||
dbc.Card( | ||
dbc.CardBody([html.Div(id="file-content-gm")]), | ||
) | ||
) | ||
) | ||
# mg tab content | ||
mg_content = dbc.Row( | ||
dbc.Col( | ||
dbc.Card( | ||
dbc.CardBody([html.Div(id="file-content-mg")]), | ||
) | ||
), | ||
) | ||
# tabs | ||
tabs = dbc.Row( | ||
dbc.Col( | ||
dbc.Tabs( | ||
[ | ||
dbc.Tab( | ||
gm_content, | ||
label="Genomics -> Metabolomics", | ||
activeTabClassName="fw-bold", | ||
disabled=True, | ||
id="gm-tab", | ||
className="disabled-tab", | ||
), | ||
dbc.Tab( | ||
mg_content, | ||
label="Metabolomics -> Genomics", | ||
activeTabClassName="fw-bold", | ||
disabled=True, | ||
id="mg-tab", | ||
className="disabled-tab", | ||
), | ||
], | ||
), | ||
), | ||
className="p-5", | ||
) | ||
|
||
# ------------------ App Layout ------------------ # | ||
app.layout = dbc.Container([navbar, uploader, tabs], fluid=True, className="p-0") | ||
|
||
# ------------------ Callbacks------------------ # | ||
clientside_callback( | ||
""" | ||
(switchOn) => { | ||
document.documentElement.setAttribute('data-bs-theme', switchOn ? 'light' : 'dark'); | ||
return window.dash_clientside.no_update | ||
} | ||
""", | ||
Output("color-mode-switch", "id"), | ||
Input("color-mode-switch", "value"), | ||
) | ||
|
||
|
||
@du.callback( | ||
id="dash-uploader", | ||
output=[Output("dash-uploader-output", "children"), Output("file-store", "data")], | ||
) | ||
def upload_data(status: du.UploadStatus): # noqa: D103 | ||
if status.is_completed: | ||
latest_file = status.latest_file | ||
with open(status.latest_file, "rb") as f: | ||
pickle.load(f) | ||
return ( | ||
f"Successfully uploaded: {os.path.basename(latest_file)} [{round(status.uploaded_size_mb, 2)} MB]", | ||
str(latest_file), | ||
) | ||
return "No file uploaded", None | ||
|
||
|
||
@app.callback( | ||
[Output("gm-tab", "disabled"), Output("mg-tab", "disabled")], | ||
[Input("file-store", "data")], | ||
prevent_initial_call=True, | ||
) | ||
def disable_tabs(file_name): # noqa: D103 | ||
if file_name is None: | ||
# Disable the tabs | ||
return True, True | ||
# Enable the tabs | ||
return False, False | ||
|
||
|
||
# Define another callback to access the stored file path and read the file | ||
@app.callback( | ||
[Output("file-content-gm", "children"), Output("file-content-mg", "children")], | ||
[Input("file-store", "data")], | ||
) | ||
def display_file_contents(file_path): # noqa: D103 | ||
if file_path is not None: | ||
with open(file_path, "rb") as f: | ||
data = pickle.load(f) | ||
# Process and display the data as needed | ||
content = f"File contents: {data[0][:2]}" | ||
return content, content # Display same content in both tabs | ||
return "No data available", "No data available" | ||
|
||
app.layout = create_layout() | ||
|
||
if __name__ == "__main__": | ||
app.run_server(debug=True) |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.