I have code as below:
from dash import Dash, html, dcc, Input, Output, State, no_update, clientside_callback
app = Dash(
name=__name__,
)
app.layout= html.Div([
html.Button("click1", id="button1"),
html.Button("click2", id="button2"),
dcc.Input(id="input1"),
html.Div(id="echo"),
html.Div(id="echo2"),
])
clientside_callback(
'''
function (x){
document.getElementById('input1').value="test";
return ""
}
''',
Output("echo", "children"),
Input("button1", "n_clicks"),
prevent_initial_call = True,
)
@app.callback(
Output("echo2", "children"),
Input("button2", "n_clicks"),
State("input1", "value"),
prevent_initial_call = True,
)
def PrintInput(x, value):
if x is None:
return None
return str(value)
server = app.server
if __name__ == "__main__":
app.run_server(
debug=True,
port=8050
)
What I want to do is user can click button1 to set value to input1 via a clientside_callback. This was simulation of user barcode scanning so I think I canât make it through normal callback. Then I want to use the value of input1 set before, which is clicking button2 to show in echo2 here. But by this way I canât get value of input1 in python. How to improve the code to get it? Thanks very much for your help.