Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating page_registry from a callback #85

Closed
bigmike36c opened this issue Mar 7, 2022 · 3 comments
Closed

Updating page_registry from a callback #85

bigmike36c opened this issue Mar 7, 2022 · 3 comments

Comments

@bigmike36c
Copy link

Hello,
I think I found a bug when attempting to update the page_registry from a callback. The main issue I’ve been facing with this approach is the redirects do not seem to work. Inspecting the page_registry shows that the redirect_from parameter has the proper list of values (e.g. in the code below 'redirect_from': ['/callback-page']). But entering this in the url always returns the 404 page. However, when using the redirects with a page defined outside a callback, it works without issue.

I worked up a quick example demonstrating the issue.

import dash
from dash import html, Output, Input
import dash_labs as dl

import dash_bootstrap_components as dbc

app = dash.Dash(__name__, plugins=[dl.plugins.pages])
server = app.server

dash.register_page(
    "historical_analysis",
    path="/historical-analysis",
    redirect_from=["/test"],
    layout=html.Div(["Historical Analysis Page"]),
)
dash.register_page(
    "forecast",
    path="/forecast",
    layout=(html.Button("Button", id="button"), html.Div(id="content")),
)

app.layout = dbc.Container(
    [
        dbc.NavbarSimple(
            [
                dbc.NavItem(dbc.NavLink(page["name"], href=page["path"]))
                for page in dash.page_registry.values()
            ]
        ),
        dl.plugins.page_container,
    ]
)


@app.callback(
    Output(component_id="content", component_property="children"),
    Input(component_id="button", component_property="n_clicks"),
    prevent_initial_call=True,
)
def update_output_div(n_clicks):

    dash.register_page(
        "callback_page",
        path=f"/callback-page/{n_clicks}",
        redirect_from=["/callback-page"],
        layout=html.Div(["Callback Page"]),
    )
    return f"Output: {n_clicks}"


if __name__ == "__main__":
    app.run_server(debug=True)

And here is a short video demonstrating the unexpected behavior:
Screen Recording 2022-03-06 at 6 20 06 PM

My main use case for this is with dash enterprise's dashboard engine. When the user saves a dashboard, it creates a unique snapshot_id and I generate new pages for viewing and editing this dashboard.

Thanks in advance for any help!

@AnnMarieW
Copy link
Collaborator

AnnMarieW commented Mar 7, 2022

Thanks for reporting @bigmike36c

This has been fixed in the dash PR plotly/dash#1947 (review)

@AnnMarieW
Copy link
Collaborator

Hey @bigmike36c
Thanks for closing this, but I think it's best to keep it open until we decide if dash-labs should be updated as well.

@AnnMarieW AnnMarieW reopened this Mar 7, 2022
@AnnMarieW
Copy link
Collaborator

@bigmike36c
I just wanted you to know that this issue will be closed and the change will be removed from the dash PR as well. Even though the change seemed to work locally, it would most likely fail in production in a multi-user environment -- unless (a) these updates, even though initiated by one user, are intended to apply to all users, and (b) you’ve done something to make it work cross-process, like sharing the updates to the other processes via redis.

Feel free to re-open if you have any more questions or comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants