Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Return calculated results based on callback inputs


Apologies if this is a silly question. I am still learning. I want to take in a series of inputs, and based on each input, return a calculated result as an output for the user to see.

Please see an example below:

dash.dependencies.Output(‘output-state’, ‘children’),
[dash.dependencies.Input(‘submit-button’, ‘n_clicks’)],
State(‘length’, ‘value’),
State(‘count’, ‘value’),
State(‘depth’, ‘value’),
State(‘hdd’, ‘value’)])
def update_output(n_clicks,line,length,count,depth,hdd):
if pipeline == ‘QC’:
if length == ‘E’:
return 'Total Size is {} '.format(count*12)

The above is treating count as a string instead of an integer, even though the original input has type=‘number’.

Please let me know how I might be able to do this in an efficient way.


Apologies for the trigger happy post:

The answer is to simply convert the value to an int using int(), like so:

return 'Total Size is {} '.format(int(count)*12)