I want to have a button to upload a file, and when a file is selected, it should say ‘file uploaded’ next to the button. For that, I have the following code, where I have specified style={'display': 'inline-block'}
in both the upload component and the div component:
import dash
from dash.dependencies import Output, Input, State
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
server = app.server
app.layout = html.Div(children = [
html.Div([
dcc.Upload(id='upload_file', children=[html.Button('Upload File', id='file_upload_btn', n_clicks=0, style={'width': '240px', 'height':'40px'})], style={'display': 'inline-block'}),
html.Div(id='file_upload_success', style={'display': 'inline-block'})
])
])
@app.callback(Output('file_upload_success', 'children'),
Input('file_upload_btn', 'n_clicks'),
Input('upload_file', 'contents'),
State('upload_file', 'filename'))
def update_success_message(n_clicks, contents, filename):
if n_clicks and contents:
return "File '{}' uploaded".format(filename)
if __name__ == '__main__':
app.run_server(debug=True)
But it does not display the text beside the button - it displays the text below the button, as if its ignoring the style={'display': 'inline-block'}
part. Why is that, and how do I fix it?