forked from OpenMS/streamlit-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0c66ce
commit e9d24c7
Showing
4 changed files
with
95 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import streamlit as st | ||
|
||
from os.path import join, exists, dirname, isfile, basename | ||
from os import listdir | ||
|
||
from src.common import page_setup | ||
from io import StringIO, BytesIO | ||
from zipfile import ZipFile, ZIP_DEFLATED | ||
|
||
|
||
def content(): | ||
page_setup("TaggerViewer") | ||
|
||
dirpath = join(st.session_state["workspace"], 'FLASHTaggerOutput') | ||
|
||
if exists(dirpath): | ||
directories = sorted( | ||
[entry for entry in listdir(dirpath) if not isfile(entry)] | ||
) | ||
else: | ||
directories = [] | ||
|
||
if len(directories) == 0: | ||
st.error('No results to show yet. Please run a workflow first!') | ||
return | ||
|
||
# Table Header | ||
columns = st.columns((0.4, 0.6)) | ||
columns[0].write('**Run**') | ||
columns[1].write('**Download**') | ||
|
||
# Table Body | ||
for i, directory in enumerate(directories): | ||
st.divider() | ||
columns = st.columns((0.4, 0.6)) | ||
columns[0].empty().write(directory) | ||
|
||
with columns[1]: | ||
button_placeholder = st.empty() | ||
|
||
clicked = button_placeholder.button('Prepare Download', key=i) | ||
if clicked: | ||
button_placeholder.empty() | ||
with st.spinner(): | ||
out_zip = join(dirpath, directory, 'output.zip') | ||
if not exists(out_zip): | ||
with ZipFile(out_zip, 'w', ZIP_DEFLATED) as zip_file: | ||
for output in listdir(join(dirpath, directory)): | ||
try: | ||
with open(join(dirpath, directory, output), 'r') as f: | ||
zip_file.writestr(basename(output), f.read()) | ||
except: | ||
continue | ||
with open(out_zip, 'rb') as f: | ||
button_placeholder.download_button( | ||
"Download ⬇️", f, | ||
file_name = f'{directory}.zip' | ||
) | ||
|
||
if __name__ == "__main__": | ||
content() |
This file contains 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
This file contains 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