The example below is from the dash user guide. Here the user enters some text into 2 text boxes and clicks a submit bottom.
I’m new to all of this and don’t fully comprehend whats going on with callbacks, states etc.
I am trying to simply get the inputted text from the browser and store it in a string variable so I can work with it, Something like this:
x = str(input1) + " " + str(input2)
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
external_stylesheets = [‘https://codepen.io/chriddyp/pen/bWLwgP.css’]
app = dash.Dash(name, external_stylesheets=external_stylesheets)
app.layout = html.Div([
dcc.Input(id=‘input-1-submit’, type=‘text’, value=‘Montréal’),
dcc.Input(id=‘input-2-submit’, type=‘text’, value=‘Canada’),
html.Div(id=‘output-submit’)
])
@app.callback(Output(‘output-submit’, ‘children’),
[Input(‘input-1-submit’, ‘n_submit’), Input(‘input-1-submit’, ‘n_blur’),
Input(‘input-2-submit’, ‘n_submit’), Input(‘input-2-submit’, ‘n_blur’)],
[State(‘input-1-submit’, ‘value’),
State(‘input-2-submit’, ‘value’)])
def update_output(ns1, nb1, ns2, nb2, input1, input2):
return u’’’
Input 1 is “{}”,
and Input 2 is “{}”
‘’’.format( input1, input2)
if name == ‘main’:
app.run_server(debug=True)