是否有人知道我是否正确设置了此按钮(用于Dash),以便能够读取下拉列表和上载功能的输入?我的app.callback()呢? 我需要一些帮助来分析为什么当我点击submit而什么也没发生时它不能正常工作
#Uploading file definitions
def save_file(name, content):
"""Decode and store a file uploaded with Plotly Dash."""
data = content.encode("utf8").split(b";base64,")[1]
with open(os.path.join(UPLOAD_DIRECTORY, name), "wb") as fp:
fp.write(base64.decodebytes(data))
def uploaded_files():
"""List the files in the upload directory."""
files = []
for filename in os.listdir(UPLOAD_DIRECTORY):
path = os.path.join(UPLOAD_DIRECTORY, filename)
if os.path.isfile(path):
files.append(filename)
return files
def file_download_link(filename):
"""Create a Plotly Dash 'A' element that downloads a file from the app."""
location = "/download/{}".format(urlquote(filename))
return html.A(filename, href=location)
@app.callback(
Output("file-list", "children"),
[Input("upload-data", "filename"), Input("upload-data", "contents")],)
def update_output(uploaded_filenames, uploaded_file_contents):
"""Save uploaded files and regenerate the file list."""
if uploaded_filenames is not None and uploaded_file_contents is not None:
for name, data in zip(uploaded_filenames, uploaded_file_contents):
save_file(name, data)
files = uploaded_files()
if len(files) == 0:
return [html.Li("No files yet!")]
else:
return [html.Li(file_download_link(filename)) for filename in files]
#Callback for dropdown menu
@app.callback(dash.dependencies.Output('dd-output-container', 'children'),[dash.dependencies.Input('Categories', 'value')])
def update_output_dropdown(value):
return 'You have selected "{}"'.format(value)
#Callback for submitting everything.
@app.callback(Output('target', 'children'), Input('submit', 'n_clicks'))
def callback(n_clicks):
if (n_clicks != 0):
#Read the uploaded file and calculate the category from dropdown
for file in uploaded_files():
with open(file) as f:
dfs = pd.read_excel(file)
xl = pd.ExcelFile(dfs)
if xl.parse(sheet_name= 'Spikes'):
这是一个视觉: Visual
目前没有回答
相关问题 更多 >
编程相关推荐