An idea for an API change that I’d be interested in your opinions on. I am assuming it is technically possible, but correct me if I’m wrong.
Rather than requiring Output() to be specified against a callback, could it be specified at the property that it is actually changing?
Here’s what it might look like to replace the version in the user guide
app.layout = html.Div([
dcc.Input(id='my-id', value='initial value', type='text'),
html.Div(id='my-div', children=dash.compute(update_output_div))
])
@app.callback(
[Input(component_id='my-id', component_property='value')]
)
def update_output_div(input_value):
return 'You\'ve entered "{}"'.format(input_value)
The benefits I see are:
- With any reasonably large Dash app, it would be clear to see which components had dynamic properties and which were static. You can also use IDE features to get to the callbacks instantly, or to navigate to all uses of a callback.
- There might be a clear way to specify the default value (e.g.
children=dash.Compute(theCallback, default="Loading..."
), whereas at present it’s unclear if we specify a value for a component whether that gets overridden immediately by the callback. - An obvious way to add multiple outputs from a callback without too much noise above the callback.
- More consistency with React, which is helpful for those familiar with React or who want to try making new Dash-React components.
I guess a similar idea would be to be able to specify Input components by their python reference, rather than relying on their Id. That would also improve IDE support, but I don’t think would be as popular as the Output idea, because you would have to declare and then import variables to take advantage of it.