Black Lives Matter. Please consider donating to Black Girls Code today.

Optional Input to callback?

Hi,

I’m wondering, whether it’s possible to have an optional Input to callback. I have a code like this:

  @app.callback(
            [
                Output("url", "pathname"),
                Output("hidden_div_for_drillthrough_store", "data"),
            ],
            [
                Input("specialism-overview-table", "active_cell"),

                #Input("activities-overview-poorters-table", "active_cell") # TODO ok, cant add, as they never exist together
            ],
            [State("specialism-overview-table", "data")],
        )
    def drill_to_specialism_view(active_cell,  table_data):
....

This callback is used to drillthrough to a different page. At the moment, only single input is available, which is a dash_table.DataTable.active_cell event from table “A”. This work without any issues.

As i have a multiple page app, i would like to add multiple inputs to this callback, each taking the same event, but from different tables (“B”, “C” etc.).

These tables are created dynamically on every separate page, therefore there is no possibility, that there are multiple tables shown at any given time. Hoverver, i cant define the callback to take multiple Inputs, due to missing property ID (which is kinda obvious, as only single table exists at any given time.)

So the question is, whether it’s possible to define an optional Input to callback?
Or somehow dynamically define a callback Input based on possible property IDs?

Thank in advance for any suggestions.

Pavel

To my knowledge, this is not possible with the current version on Dash (work is currently underway to make Dash more dynamic, see e.g. the wild card props concept [1]).

Regarding your current problem, I guess that the quickest work-around would be to add empty, hidden tables to the other pages so that all IDs are present at all times.

A better solution, which would require more work though, would be to change the navigation and state architecture. The navigation could be performed via links, and the state (your “data”) could be stored in the session or in some server side cache. This way, you wouldn’t need any hacks :slight_smile:

[1] https://github.com/plotly/dash/issues/475