📣 Introducing Dash `/pages` - A Dash 2.x Feature Preview

Updating from 4.1 with dash_labs plugin to 5.1 without dash_labs plugin, the pages of my app disappeared.
I commented import dash_labs as dl and plugins=[dl.plugins.pages], in

app = dash.Dash(
    __name__,
    # plugins=[dl.plugins.pages],
    external_stylesheets=[dbc.themes.BOOTSTRAP],
)

and I changed dl.plugins.page_container to dash.page_container, but I guess that multipage apps migrating from plugin to 5.x need some more fixes.

Any clue?

Which operating system are you using? I recently found a bug on Windows and made a fix, but I’m not sure that it has been included in a release yet.

The app runs on Ubuntu 20.04 installed upon WSL2/Windows10.

Hmm, it could possibly be the same issue I ran into on Windows. Long story short, Windows handles paths slightly different than Unix based systems, like Ubuntu and MacOS. The pages feature was not accounting for this difference.

I’m not super familiar with the Windows Linux subsystem and how the paths work, but this could be the case.

A fix is coming soon for the paths problem, but I’m not 100% sure if this will fix your issue or not.

My app works fine with dash-labs plugin and dash 4.1, so the issue preventing my app to work with dash 5.x should have been introduced while moving dash-labs code to dash 5.x.

Is it possible to have a look at the issue/fix you are talking about?

Hi @nopria - The issue that @raptorbrad was referring to was fixed in dash 2.5.1.

Here are the steps to go from the dash-labs plug-in to dash. It looks like you might have missed step 2. Can you let me know if this works for you?


Convert your multi-page app from a dash-labs pages plug-in to the pages feature in dash 2.5.1 in 3 easy steps:

  1. Remove import dash_labs as dl or upgrade dash-labs to V1.1.0
    There is a conflict between dash-labs versions less than 1.1.0 when running a pages app in dash 2.5.1

  2. Change:

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

to:

app = Dash(__name__, use_pages=True)
  1. Change:
dl.plugins.page_container

to:

dash.page_container

That’s it!

:point_right: Thepages feature will no longer be developed in dash-labs. I recommend all dash-labs multi-page apps be converted to use the pages feature in dash>= 2.5.1

4 Likes

Yes, it works! Step 2 was missing, thanks!!

1 Like

Hello all,
can someone please help me with this error.
I am stuck with a error in build exe file of my multipage dash app. I am using cx_Freeze library to build my exe file.
After successfully building exe file, and run the my app.exe:
windows console display an error that pages folder does not exist as a result, I am unable to navigate through my different pages of my app.

I tried with (dash version2.31+dash labs 1.06) and (dash version 2.5.1+1.10) both yield me same error.
Note: The dash plugins for pages works perfectly fine when I run my code in Vscode.

any pointers would be really helpful
Thanks

*** UPDATE ***

While my answer below might work, it’s not the right way. Please see the correct solution in this post:



Original answer -(don’t do it this way - see above)

Hi @Harsha_Dreamer

I haven’t tried making an exe file from a pages app, but here is how you can make it so dash does not look for the pages folder. Basically, you do this by registering each page in app.py instead of from within the pages folder.

Note - this will only work ind dash>=2.5.1

Assuming you have a project structure that looks like this:

- app.py
- pages
    |-page1
    |-page2
  1. Remove dash.register_page(__name__) from pages.page1 and pages.page2

  2. Then in app.py, import each page:

from pages import page1, page2
  1. Register the page in app.py. You will have to assign the layout and give each a unique module name rather than using __name__ ,
dash.register_page("page1", path="/", layout=page1.layout)
dash.register_page("page2, layout=page2.layout)
  1. Set the name of the pages folder to ""
app = dash.Dash(__name__, use_pages=True, pages_folder="")

Please let me know if this works for you and it’s possible to create an exe file.

1 Like

Hi@AnnMarieW

Thanks for quick response.
I am able to register pages on code level and check with print(dash.register_pages.values()) statement but the Layout is not displaying
just curious, In step 3:

dash.register_page(“page1”, path=“/”, layout=page1.layout)

layout=page1.layout , I have defined as string ‘layout=page1.layout’

if I don’t define this as a string then there is an error saying that page1 is not defined so on so forth for other pages also.

Am I missing something?

Thanks

1 Like

@Harsha_Dreamer - it can’t be a string like this: ‘layout=page1.layout’. It looks like you skipped step 2 with importing the modules from the pages folder.

You can see a complete example in my multi-page-apps-demo repo.

Can you try running that example to see if it works?

Hi@AnnMarieW

Thanks for repo link. There were minor changes required to build exe.

I was able to build exe and run it successfully. The exe is functioning correctly for all pages except in one page where I am running Machine Learning .
In ML page, I have used process ProcessPoolExecutor() module to do carry out repeated tasks parallel. In my Vscode the ProcessPoolExecutor() is running fine. But as, I run exe file, the exe just keeps loading ML page doesn’t give any output. Is it possible to throw some light on this error?

Can you help with any documentation on how to connect dash app to SQL DB for live updates?

Thanks for the help

@Harsha_Dreamer

Can you please say what minor changes are required to build the exe? If you open an issue on the repo, I’ll update the code.

I don’t have experience using ProcessPoolEecuter() or SQL DB, But if you open a separate topic, someone in the community may be able to help.

@AnnMarieW

There are no changes in repo, minor mistakes were in my code:

I was doing (which is a mistake from my end):

dash.register_page(“page1”, path=“/”, layout=page1.layout)
dash.register_page(“page2”, layout=page2.layout)

app = dash.Dash(name, use_pages=True, pages_folder=“”)

where I should be doing:

app = dash.Dash(name, use_pages=True, pages_folder=“”)

dash.register_page(“page1”, path=“/”, layout=page1.layout)
dash.register_page(“page2”, layout=page2.layout)

Sure, I shall open a separate topic, hopefully some one will help out.

Thanks for the help

@AnnMarieW
Hi, I’m having trouble running any multi-paged app. I’ve tried creating a new venvironment and installing the new Dash version from the start but it keeps failing.

This is what appears in the web browser after running the app. There’s no problem when running single page apps.

Thanks in advance!

pip install dash==2.5.1 seemed to fix it for me, or if you try refreshing the page this also works. As Dash 2.6.0 just dropped last week, this bug might not be reported?

Thanks for the response! Now it’s working :slight_smile:

Thanks for posting the workaround @robin1010101 - and welcome to the dash community! :slightly_smiling_face:

You are correct - this was a new bug in 2.6.0, and will be fixed in 2.6.1 to be released soon.

3 posts were split to a new topic: How to build exe file of multipage dash app

Hey @AnnMarieW
Do you have a published example of a Dash app that has a URL string at the end where specific parameter is provided to parameterize the Dash app itself when it starts up?
Asking for a friend, and not sure where to best search …