0

Right now, I have code to display a graph where one can give a range for both x and y values.

This is what my output currently is. Now, I want to include a button that has another input to redirect to a new page.

Is it possible to do that? As the documentation has only either multiple inputs or multiple outputs, not both.

This is my @callback code:

@callback(
    Output('main', 'figure'),
    Input('minNodes', 'value'),
    Input('maxNodes', 'value'),
    Input('minEdges', 'value'),
    Input('maxEdges', 'value'),
)
  • 1
    You _can_ have both multiple inputs and multiple outputs. I'm not sure to understand what you are trying to do, "_I want to include a button that has another input to redirect to a new page_", maybe with `dcc.Location()` component ? see [Redirect to a url in dash](https://stackoverflow.com/q/75725718/2529954) – EricLavault Apr 13 '23 at 13:30

1 Answers1

0

You can definitely pass multiple inputs and outputs both in a single callback.
To redirect to new page you can add dcc.Location in your layout and set the url in callback on input button click.
If you need to distinct the output generation in your callback based on which input change, you can check the context trigger_id in callback.

from dash import ctx
from dash.dash import no_update
@callback(
    Output('main', 'figure'),
    Output('location', 'href')
    Input('btn_id', 'n_clicks'),
    Input('minNodes', 'value'),
    Input('maxNodes', 'value'),
    Input('minEdges', 'value'),
    Input('maxEdges', 'value'),
)
def redirect_to_url(btn_click,min1,max1,min2,max2):
    triggered_id = ctx.triggered_id
    if triggered_id == 'btn_id':
        url = 'https:www.google.com'
        return no_update, url
    else: # call when other inputs have changed
        # displaygraph 
        return graph(), no_update
Garima
  • 11
  • 2