I am using dcc.Upload
dcc.Upload(
id='upload-data',
children=html.Div([
"Drag and Drop or ",
html.A('Select Fasta Files')
]),
style={
'width': '100%',
'height': '60px',
'lineHeight':'60px',
'borderWidth': '1px',
'borderStyle': 'dashed',
'borderRadius': '5px',
'testAlign': 'center',
'margin': '10px'
},
multiple=True
),
It is a carbon copy of the first example in the documentation.
I use the example callback almost as it is to read in and output protein sequence files with a .fasta
suffix.
def register_entrez_callbacks(app):
# callbacks for entrez_page
# callbacks for processing file uploadprocessing file upload
@app.callback(Output('output-data-upload', 'children'),
[Input('upload-data', 'contents')],
[State('upload-data', 'filename'),
State('upload-data', 'last_modified')])
def process_upload(list_of_contents, list_of_names, list_of_dates):
print(f"listContents: {type(list_of_contents)}\n{list_of_contents[0]}")
print(f"listFilename: {type(list_of_names)}\n{list_of_names[0]}")
print(f"listModified: {type(list_of_dates)}\n{list_of_dates[0]}")
if list_of_contents is not None:
children=[
parse_contents(c,n,d) for c,n,d in
zip(list_of_contents, list_of_names, list_of_dates)
]
return children
# helpers for functions
# for uplaod
def parse_contents(contents, filename, date):
content_type, content_string, = contents.split(',')
print(f'name:{type(filename)}\n{filename}\n')
print(f'type:{type(content_type)}\n{content_type}\n')
print(f'string:{type(content_string)}\n{content_string}\n')
decoded = base64.b64decode(content_string)
print(f'decoded:{decoded}\n')
#seq1 = SeqIO.read(decoded, "fasta")
seq_str = str(decoded)
print(f'seq_str: {seq_str}')
'''
try:
seq = SeqIO.read(decoded, "fasta")
print(f'\n\nseq:{seq}')
except Exception as e:
print(e)
return html.Div([
'Error processing file upload'
])
'''
return html.Div([
html.H5(filename),
html.H6(datetime.datetime.fromtimestamp(date)),
html.Div(
f'{seq_str}'
),
html.Hr(),
#debugging content
html.Div('Raw Content'),
html.Pre(contents[0:100] + '...', style={
'whiteSpace': 'pre-wrap',
'wordBreak': 'break-all'
})
])
My layout also has:
html.Div(#show the uploaded file contents as string
id="output-data-upload"
),
I can see it in the browser, inspect it and it’s there.
along the right column that is the result, I can see the contents of the fasta file and the raw content.
But the errors that I hid for that screenshot:
Is this a bug and if so is it safe to just ignore it?