Multiple Outputs from Single Input with one callback

I know that, at present, we cannot have Multiple Outputs from Single Input with one callback. I have to call multiple callbacks for multiple outputs via a loop. No problem there.

In my case, I’m populating 4 drop-downs with a list of options via a callback which takes a certain input from another drop-down and makes a call to the website to get a list & populate these 4 drop-downs with same content. So, I have to do 4 callbacks to populate 4 drop-downs & therefore make 4 calls to the website.

To me, this is redundant, time consuming & wastage of resources. Ideally, I should make only one call to the website.

To save some bandwidth & time, at present, I’m making a call to the website, get the list of options, output it to a disabled drop-down and use this drop-down as input to populate the 4 drop-downs via a callback loop.

It would be nice, if in place of the disabled drop-down to have something else to hold values from which we can output it to several drop-down or any other property.

I hope I’m clear.

If anyone has any other solution, please let me know.

Thanks for the use case @raghunath!

For now, your best bet would probably be to send the data back in JSON serialized form to the front-end to a hidden html.Div and read from that. You could also add caching to the function that retrieves the data from the website (docs on caching).

There are some more details about this in this issue: https://github.com/plotly/dash/issues/49#issuecomment-311511286

Thanks, that’s nice. I was doing the same but instead of hidden DIV I was outputting to a disabled drop down. Cosmetically, hidden DIV is much better than a disabled drop-down.

I’m already using caching but my drop-down list is huge, so cache benefits the frequently used ones.

Thanks again for this great tool. Enjoying it a lot for my data-viz studies.

1 Like

Not an entirely related query but is there a way we can control same output via different states

Let’s say I generated a graph/chart with a general Input/Output method but now if I want to refresh the same chart I will have to go to the input method (drop-down in this case) and re-select the input again.

Instead, if we have a Refresh Button (n_clicks) which will simply refreshes the graph/chart without any change in input values.

Asking this because right now Dash doesn’t allow targeting same Output ID twice, so not possible.

Is it possible to have this capability? @chriddyp

Wouldn’t something like:

@app.callback(Output('graph', 'figure'),
    [Input('dropdown', 'value'), Input('button', 'n_clicks')])

work in this case?

1 Like

Damn, never thought of it this way. Presumed that it would need both Inputs together for the output to work. Wrong assumption.

Thanks @chriddyp for the solution.

1 Like