I have been searching but I can’t find a solution, I am guessing it is a simple problem. I am trying to represent a button as an icon.
Take for example, the following code from Dash User Guide:
@chriddyp@tcbegley I want to get the value of the button when it is clicked.
import dash
import dash_html_components as html
import dash_core_components as dcc
import dash_bootstrap_components as dbc
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
html.Div(dbc.Input(id='input-box', type='text')),
dbc.Button('ButtonValue', id='button'),
html.Div(id='container-button-basic',
children='Enter a value and press submit')
])
@app.callback(
dash.dependencies.Output('container-button-basic', 'children'),
[dbc.Input('button', 'value')], )
def update_output(value):
return 'The input value was "{}" and the button has been clicked {} times'.format(
value, value
)
if __name__ == '__main__':
app.run_server(debug=True)
Above is my code and it gives an Incorrect Type Exception.
Your question is completely unrelated to the post and you should have made a new post regarding your problem.
Also you should definitely check out the dash user guide at https://dash.plot.ly
Anyways regarding your problem:
@app.callback(
Output('container-button-basic', 'children'),
[Input('button', 'n_clicks')],
[State('input-box', 'value')]
)
def update_output(clicks, value):
if clicks is None:
raise PreventUpdate
return 'The input value was "{}" and the button has been clicked {} times'.format(value, clicks)