I made a multi-page app and once I change my url to shift one page to another page or even when I refresh the current page, there will be a duplicate callback output error.
Besides, I encapsulated my function into a function and return the layout to my index.py to show it, but it seems like all the callbacks are not shown when I open the url, only if I refresh the page will it update the callbacks.
I have totally no idea, is there anyone to help me with that? Thanks a lot
I have the same problem but still can’t figure it out
In Dash, you can only assign at most one callback to target an item (Output(...)) in the layout.
Below is not possible (it’s just to demonstrate the point):
@app.callback(
Output("some-element-id", "children"),
[Input(...)]
)
def do_something():
# ...
@app.callback(
Output("some-element-id", "children"),
[Input(...)]
)
def do_another_thing():
# ...
I’m wondering if you have duplicate code for each of your pages in your multi-page app.
Would you mind posting your code in this thread?
I also encountered this error when I moved a callback from outside of a function that is returned to within that function. For example in index.py which sets my layout for my multipage app:
@app.callback(Output('page-content', 'children'),
[Input('url', 'pathname')])
def display_page(pathname):
if pathname is None:
home = layout_function(pathname)
return home
And then in my home.py app:
# I moved the some-element-id callback into layout_function from outside of it.
def layout_function(pathname):
@app.callback(
Output("some-element-id", "children"),
[Input(...)]
)
def do_something():
# ...
return home_layout
# Previously this was outside the function and worked fine.
@app.callback(
Output("some-element-id", "children"),
[Input(...)]
)
def do_another_thing():
# ...
It seems like the callbacks within my function are being sent again.
This issue is in dash 1.6.0 though it seems like pattern matching callback may actually fix my issue. Perhaps I need to upgrade.
Have you found a solution to this problem, I am having the same problem but don’t know how to solve it. If you have any good ideas, please let me know.Thanks
I had the same problem and it seems that you can’t define callbacks inside something generated by other callback. In my case, I had some tabs and I wanted a sidebar to change with the tab. I was defining some other callbacks insede this changing sidebar, which i found to be the problem. I just changed where I was defining them.
