Pattern-matching callbacks not triggered, producing TypeErrors 'unexpected keyword argument'
Running a Dash app that uses pattern-matching callbacks by itself works fine but as soon as DjangoDash is being imported, the following error shows up even if the app is run standalone outside of Django:
TypeError: callback_test() got an unexpected keyword argument 'background_callback_manager'
I can work around the issue by adding all keyword arguments it's complaining about and run the Dash app on its own with working callbacks but as soon as I run it within Django, the callbacks won't work:
def callback_test(n_clicks, background_callback_manager=None, callback_context=None, app=None, app_on_error=None, app_use_async=None):
dash==3.2.0 dash-bootstrap-components==2.0.3 dash-core-components==2.0.0 dash-extensions==2.0.4 dash-html-components==2.0.0 dash-table==5.0.0 dash-tvlwc==0.1.1 django-plotly-dash==2.5.0
@notgonnamakeit do you have a simple example app/script that exhibits this issue? Doesnt have to do anything interesting except generate the error when importing DjangoDash as you describe.
Sorry for the late reply, got swamped with different things. Here's a simple example, I think it's from the plotly website. The import of DjangoDash creates the behaviour even though it's not used. Same behaviour in a Django app.
# TypeError: display_dropdowns() got an unexpected keyword argument 'background_callback_manager'
# If you remove the following import, the app works fine
from django_plotly_dash import DjangoDash
# everything from here works
from dash import Dash, dcc, html, Input, Output, ALL, Patch, callback
app = Dash()
app.layout = html.Div(
[
html.Button("Add Filter", id="add-filter-btn", n_clicks=0),
html.Div(id="dropdown-container-div", children=[]),
html.Div(id="dropdown-container-output-div"),
]
)
@callback(
Output("dropdown-container-div", "children"), Input("add-filter-btn", "n_clicks")
)
def display_dropdowns(n_clicks):
patched_children = Patch()
new_dropdown = dcc.Dropdown(
["NYC", "MTL", "LA", "TOKYO"],
id={"type": "city-filter-dropdown", "index": n_clicks},
)
patched_children.append(new_dropdown)
return patched_children
@callback(
Output("dropdown-container-output-div", "children"),
Input({"type": "city-filter-dropdown", "index": ALL}, "value"),
)
def display_output(values):
return html.Div(
[html.Div(f"Dropdown {i + 1} = {value}") for (i, value) in enumerate(values)]
)
if __name__ == "__main__":
app.run(debug=True)