Skip to content

Allow to load pages from package#2556

Open
rnestler wants to merge 2 commits intoplotly:devfrom
rnestler:allow-to-load-pages-from-package
Open

Allow to load pages from package#2556
rnestler wants to merge 2 commits intoplotly:devfrom
rnestler:allow-to-load-pages-from-package

Conversation

@rnestler
Copy link
Copy Markdown
Contributor

@rnestler rnestler commented Jun 1, 2023

This allows to load the pages from an imported python package which is recursively scanned. This is useful if one compiles an application using Cython where the modules are then not .py files anymore, but compiled .so files.

In our application we compile everything with Cython in the end, to get some performance gains. Since the current implementation of the pages feature only searches for .py files in the pages folder I worked around it in our application using this approach.

Would this be a feature of general interest? IMO it is nice, since the implementation is way simpler and it uses built in tools to load the modules.

Contributor Checklist

  • I have broken down my PR scope into the following TODO tasks
    • Agree that this is a useful feature
    • Agree on the naming of the new parameter
    • Add documentation for the new parameter
    • Add more tests
  • I have run the tests locally and they passed. (refer to testing section in contributing)
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR

optionals

  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follows
    • this GitHub #PR number updates the dash docs
    • here is the show and tell thread in Plotly Dash community

@rnestler rnestler requested a review from alexcjohnson as a code owner June 1, 2023 17:06
@rnestler rnestler force-pushed the allow-to-load-pages-from-package branch from 282e606 to 3bb355b Compare June 2, 2023 07:55
@gvwilson gvwilson self-assigned this Jul 24, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson added feature something new P2 considered for next cycle community community contribution labels Aug 13, 2024
@gvwilson
Copy link
Copy Markdown
Contributor

Related: #2968 2968

This allows to load the pages from an imported python package which is
recursively scanned. This is useful if one compiles an application using
Cython where the modules are then not .py files anymore, but compiled
.so files.
Apparently not all tests that add modules to the PAGE_REGISTRY also add
them to sys.modules.
@rnestler
Copy link
Copy Markdown
Contributor Author

rnestler commented Apr 4, 2025

So any feedback on this?

Copy link
Copy Markdown
Contributor

@T4rk1n T4rk1n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this PR flew under my radar, this is interesting.

I think we could use the walk for the regular pages and not add another pages_package in the dash init if that works for both regular files.

There could be improvement too by allowing the pages_folder to be a list of directory to look in.

@T4rk1n
Copy link
Copy Markdown
Contributor

T4rk1n commented Nov 28, 2025

@AnnMarieW Can you take a look at this?

@AnnMarieW
Copy link
Copy Markdown
Collaborator

AnnMarieW commented Nov 28, 2025

Would the solution in this PR work? #2392

It's been available for a while but didn't get documented.

When running inside a package and the name param of the Dash instance is set to package, the module name of auto imported Pages modules will now be prefixed with the package name. ie myproj/pages/page1.py -> myproj.pages.page1 (previously would have been pages.page1). Fixes #2263

@rnestler
Copy link
Copy Markdown
Contributor Author

Would the solution in this PR work? #2392

I don't think so. It still seems to search for .py files, just loading them differntly. In my case there aren't any .py files available, since we compile it with Cython.

I think we could use the walk for the regular pages and not add another pages_package in the dash init if that works for both regular files.

I think this should work as long as there is an __init__.py in the folder where the pages are.

But I'm not currently actively working on the project were we needed this, so I don't have a lot of capacity to work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community community contribution feature something new P2 considered for next cycle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants