dash icon indicating copy to clipboard operation
dash copied to clipboard

Allow to load pages from package

Open rnestler opened this issue 2 years ago • 4 comments

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

  • [X] 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
  • [X] I have run the tests locally and they passed. (refer to testing section in contributing)
  • [X] 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 avatar Jun 01 '23 17:06 rnestler

Related: #2968 2968

gvwilson avatar Aug 28 '24 15:08 gvwilson

So any feedback on this?

rnestler avatar Apr 04 '25 13:04 rnestler

@AnnMarieW Can you take a look at this?

T4rk1n avatar Nov 28 '25 14:11 T4rk1n

Would the solution in this PR work? https://github.com/plotly/dash/pull/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 https://github.com/plotly/dash/issues/2263

AnnMarieW avatar Nov 28 '25 15:11 AnnMarieW