【发布时间】:2022-01-06 02:24:14
【问题描述】:
我正在创建一个仪表板应用程序,我可以在其中上传图像并对其执行图像处理。我已经阅读了 Dash 教程,但几乎没有关于如何在页面上定位各种元素的信息。
例如,我希望我上传的图片显示在标题的右侧和下方,“拖放...”按钮和其他滑块和复选框显示在左侧。我在下面附上了一张示例图片。
以下是我目前所拥有的:
style = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=style)
colors = {
'title': '#FFFFFF',
'text': '#AOAABA',
'background': '#161A1D'
}
app.layout = html.Div([
html.H2("Object Detection and Image Processing",
style={'textAlign':'center',
'color': colors['text']}),
html.Hr(),
html.H3("Upload Image Below To Get Started",
style={'textAlign':'center',
'color': colors['text']}),
dcc.Upload(
id='upload-image',
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
),
html.Div(id='output-image-upload'),
])
def parse_contents(contents, filename, date):
return html.Div([
html.H5(filename),
html.H6(datetime.datetime.fromtimestamp(date)),
# HTML images accept base64 encoded strings in the same format as upload
html.Img(src=contents)
])
@app.callback(Output('output-image-upload', 'children'),
Input('upload-image', 'contents'),
State('upload-image', 'filename'),
State('upload-image', 'last_modified'))
def update_output(list_of_contents, list_of_names, list_of_dates):
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
if __name__ == '__main__':
app.run_server(debug=True)
下面是我希望它的样子:
【问题讨论】:
标签: python html css plotly-dash