Python Dashboard应用程序,具有多个上载框以更新图形
我正在制作一个仪表板应用程序,您可以在其中上载一个CSV文件,并(使用plotly)绘制该文件的内容 目前,我的dashboard应用程序运行着一个上传框和三种不同类型的图形(每种图形都有回调,以便在上传文件时更新图形) 这是应用程序的当前布局Python Dashboard应用程序,具有多个上载框以更新图形,python,callback,upload,plotly,dashboard,Python,Callback,Upload,Plotly,Dashboard,我正在制作一个仪表板应用程序,您可以在其中上载一个CSV文件,并(使用plotly)绘制该文件的内容 目前,我的dashboard应用程序运行着一个上传框和三种不同类型的图形(每种图形都有回调,以便在上传文件时更新图形) 这是应用程序的当前布局 # appropriate imports app.layout = html.Div( [ html.H1(children=''), # uploader dcc.Upload(
# appropriate imports
app.layout = html.Div(
[
html.H1(children=''),
# uploader
dcc.Upload(
id='upload-data-1',
children=html.Div([
'Drag and Drop or ',
html.A('Select Files'),
]),
style={
'width': '100%',
'height': '60px',
'lineHeight': '60px',
'borderWidth': '1px',
'borderStyle': 'dashed',
'borderRadius': '5px',
'textAlign': 'center',
'margin': '10px'
},
# Allow multiple files to be uploaded
multiple=True
),
dcc.Graph(id = 'graph_1'), # choropleth map
dcc.Graph(id = 'graph_2'), # scatter plot
dcc.Graph(id = 'graph_3'), # graph
]
)
#callback 1
@app.callback(Output('graph_1', 'figure'),
[
Input('upload-data-1', 'contents'),
Input('upload-data-1', 'filename')
]
)
# function which updates graph_1
# callback 2
@app.callback(Output('graph_2', 'figure'),
[
Input('upload-data-1', 'contents'),
Input('upload-data-1', 'filename')
]
)
# function which updates graph_2
# callback 3
@app.callback(Output('graph_3', 'figure'),
[
Input('upload-data-1', 'contents'),
Input('upload-data-1', 'filename')
]
)
# function which updates graph_3
这是完全功能现在。请注意,所有三个图都是通过一次上载更新的
但是我想改变这个布局。我基本上认为graph_2和graph_3是不必要的,我想创建两个版本的graph_1,每个版本都有各自的上传框,以便查看和比较这两个图形。理论上,我希望最终版本看起来像这样
# appropriate imports
app.layout = html.Div(
[
html.H1(children=''),
# uploader
dcc.Upload(
id='upload-data-1',
children=html.Div([
'Drag and Drop or ',
html.A('Select Files'),
]),
style={
'width': '100%',
'height': '60px',
'lineHeight': '60px',
'borderWidth': '1px',
'borderStyle': 'dashed',
'borderRadius': '5px',
'textAlign': 'center',
'margin': '10px'
},
# Allow multiple files to be uploaded
multiple=True
),
dcc.Graph(id = 'graph_1_v_1'), # choropleth map 1
dcc.Upload(
id='upload-data-2',
children=html.Div([
'Drag and Drop or ',
html.A('Select Files'),
]),
style={
'width': '100%',
'height': '60px',
'lineHeight': '60px',
'borderWidth': '1px',
'borderStyle': 'dashed',
'borderRadius': '5px',
'textAlign': 'center',
#'margin': '10px'
},
# Allow multiple files to be uploaded
multiple=True
),
dcc.Graph(id = 'graph_1_v_2'), # choropleth map 2
]
)
#callback 1
@app.callback(Output('graph_1_v_1', 'figure'),
[
Input('upload-data-1', 'contents'),
Input('upload-data-1', 'filename')
]
)
# function_1, which updates graph_1_v_1
# callback 2
@app.callback(Output('graph_1_v_2', 'figure'),
[
Input('upload-data-2', 'contents'),
Input('upload-data-2', 'filename')
]
)
# Call function_1 again, only this time to update graph_1_v_2
这就是我遇到问题的地方。当我测试第一个上传框和图时,它工作得很好,我认为第二个上传框工作得很好(没有理由不工作,因为它与第一个框的代码基本相同),但是图1\u v\u 2从未得到更新。我几乎可以肯定,这是因为我的回调做得不正确。我尝试了几种不同的方法,包括将两个回调组合成一个回调,并让一个回调使用另一个回调的输出作为输入,但我仍然没有多少运气
提前谢谢 快速更新。如果我不为两个回调调用函数_1,而是创建一个与函数_1内容相同的全新函数(我们称之为函数_1_copy),那么我就能够成功地完成我想做的事情。但是函数_1是一个很长的函数,我不想重复这么多代码。快速更新。如果我不为两个回调调用函数_1,而是创建一个与函数_1内容相同的全新函数(我们称之为函数_1_copy),那么我就能够成功地完成我想做的事情。但是函数_1是一个长函数,我不想重复这么多代码。