I tried using a div containing various elements with which the user can interact and then pass the entire div element as a State
to a function to be able to read all of the various inputs.
However, it seems that the div isn’t getting updated. I wrote a small programme which shows the problem below:
import dash
import dash_html_components as html
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
app = dash.Dash(__name__)
app.css.append_css({
'external_url': ('https://stackpath.bootstrapcdn.com/'
'bootstrap/4.1.1/css/bootstrap.min.css')
})
app.layout = html.Div(
className='container-fluid',
children=[
html.Div(id='test', children=[
html.Button(id='btn', children='Press me'),
dcc.Input(id='inp', value='asdf')
]),
html.Div(id='out')]
)
@app.callback(
Output('out', 'children'),
[Input('btn', 'n_clicks')],
[State('test', 'children')]
)
def update(n, div):
print(div)
app.run_server(debug=True, port=8888)
I know that in this simple case I could just have the State
depend on the value property of the id=‘inp’ however each of these is generated dynamically so I thought I’d create whatever I create in the div and then pass the div and parse it (which I have code for). The only problem is I can’t get the div to update!