dash
dash copied to clipboard
Allow to load pages from package
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
Related: #2968 2968
So any feedback on this?
@AnnMarieW Can you take a look at this?
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