Callback that retrieves data that is not known to caller

Plotly newbie here.

The example callbacks that I see have a structure that contains both the data that is used in the caller and in the callback. I want the callback to use the data that is passed to it to then query a database to retrieve and present details unknown to the caller.

For example, the user clicks on a bar in a bar chart that shows the number of blue widgets sold in April, and is then shown a list of those blue widgets and the names of the customers who bought them. The bar chart “knows” the color and the month, but not the names of the customers.

Can this be done?

Thank you.

Hi @dshadovi welcome to the forums!

What you want to do is perfectly possible. Maybe this little example gets you an idea. In this case, the database call is just a function…

import dash
from dash import html, Input, Output

def call_database(some_input):
    # process "some_input"
    return 'database_return'

app = dash.Dash(__name__)

app.layout = html.Div(
        html.Button(children='click', id='btn'),

    Output(component_id='container', component_property='children'),
    Input(component_id='btn', component_property='n_clicks'),
def update(your_input):

    return call_database(your_input)

if __name__ == "__main__":
1 Like

Thank you! Now I’ve got some learning to do.

1 Like

Just let us know if you need further assistance :raised_hands:

1 Like