Multipage App and MultiplexerTransform
JoGruen opened this issue · comments
Hi,
I have a single page app and use MultiplexerTransform to target outputs by multiply callbacks, which works perfectly fine. Since I switched to multi page from dash 2.5.0 I get tons of errors about Duplicate callback outputs
. Is this a current limitation or am I doing a mistake?
Thanks in advance!
Versions:
dash 2.7.0
dash-extensions 0.1.7
No, with those exact versions, it should work (the 0.1.7 release is compatible only with Dash 2.7.x, 0.1.6 are compatible with Dash 2.6.x and older).
Could you post an MWE?
Thanks for your fast reply! The folder structure is as follows:
- index.py
- content.py
- pages
- first.py
The content.py
file:
import dash
from dash import html
from .index import app
app.layout = html.Div(
[
dash.page_container
],
style={"margin": "0", "height": "100%"}
)
The index.py
file:
from dash_extensions.enrich import DashProxy, MultiplexerTransform
import flask
server = flask.Flask(__name__)
app = DashProxy(
__name__,
use_pages=True,
suppress_callback_exceptions=True,
transforms=[MultiplexerTransform()],
server=server
)
if __name__ == "__main__":
app.run_server(host='localhost', port=8000, debug=True)
and the first.py
:
import dash
from dash import html
from dash_extensions.enrich import Input, Output
dash.register_page(__name__, path="/")
def layout():
return \
html.Div(
[
html.P('How are you?', id='p'),
html.Button('Press me', id='button-1'),
html.Button('Press me', id='button-2')
],
style={"margin": "0", "height": "100%"}
)
@dash.callback(Output('p', 'children'),
Input('button-1', 'n_clicks'))
def test1(n):
return 'Hello world'
@dash.callback(Output('p', 'children'),
Input('button-2', 'n_clicks'))
def test1(n):
return 'Hello world1'
I assume the problem occurs since I use @dash
instead of @app
- could this be? If so, what is the proper way of doing it?
Thanks!
Yes, that is correct. You can't use the callback imported from dash, you should use the enrich equivalent instead. It has always been that way though, so the version shouldn't matter.
In terms of syntax, you have (at least) two options. You can simply replace the import, i.e. use
from dash_extensions.enrich import callback
or you can create a DashBlueprint
object within each file (see the docs), and then register each blueprint onto the app.
Thank you! This helped a lot.