Black Lives Matter. Please consider donating to Black Girls Code today.
Dash Enterprise delivers an incredible 21x cost savings πŸ’ΈDownload the e-book!

How callback function can read an algorithm as input?

Hi all,
I am developing this dash which should take several inputs as parameters and then run an algorithm to get me the outputs as a figure. To get the figure, I want the the callback to also read the algorithm which is a function Algorithm(Parameter1,Parameter2, …). How can I let the callback read that algorithm as an input and run it?

Could you post some code/pseudo code? Where does the algorithm come from?

1 Like

Thanks @Emil for your reply! Actually I was contacted by @AnnMarieW that provided me with a way to do it which is the following:
My function is an algorithm I developed that which has the form of a function as Algorithm(Parameter1,Parameter2…). It returns a figure.

def model(parameter1, parameter2):
  x = parameter1 + parameter2  # (or whatever your model is)
  return x


@app.callback(
    Output(component_id='my-output', component_property='children'),
    [Input(component_id='my-input', component_property='value')]
)
def update_output_div(input_value):
     # use it like any other function
     x = model(input_value, parameter2)

    return 'Output: {}'.format(x)