Skip to content

Instantly share code, notes, and snippets.

@hartzell
Created June 2, 2020 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hartzell/4a7a6c1e613c1fd75aa8342936ad70ec to your computer and use it in GitHub Desktop.
Save hartzell/4a7a6c1e613c1fd75aa8342936ad70ec to your computer and use it in GitHub Desktop.
Simple sample Dash uploader script, sometimes complains 'Failed to fetch'
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
from flask import Flask
server = Flask(__name__)
app = dash.Dash(server=server)
app.layout = html.Div(
[
dcc.Store(id="jobs-store"),
html.H1("Primer Designer"),
html.H2("Upload"),
dcc.Upload(
id="upload-data",
children=html.Div(
["Drag and drop or click to select a file to upload."]
),
style={
"width": "100%",
"height": "60px",
"lineHeight": "60px",
"borderWidth": "1px",
"borderStyle": "dashed",
"borderRadius": "5px",
"textAlign": "center",
"margin": "10px",
},
multiple=True,
),
html.Ul(id="file-list"),
],
style={"max-width": "500px"},
)
@app.callback(Output("file-list", "children"), [Input("jobs-store", "data")])
def updatelist(data):
children = []
if data is not None:
children = [html.Li(j) for j in data]
return children
@app.callback(
Output("jobs-store", "data"),
[Input("upload-data", "contents")],
[State("upload-data", "filename"), State("upload-data", "last_modified"),],
)
def update_output(list_of_contents, list_of_names, list_of_dates):
"""Save uploaded files and regenerate the file list."""
if list_of_contents is not None:
children = [
n
for c, n, d in zip(list_of_contents, list_of_names, list_of_dates)
]
print(children)
return children
if __name__ == "__main__":
app.run_server(debug=True, port=8888, host="172.16.193.97")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment