-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Fix assets blueprint path management #547
Conversation
dash/dash.py
Outdated
assets_url_path='/assets', | ||
assets_ignore='', | ||
assets_blueprint_name='assets', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How important is this to be a user-configurable param? If we made the initial value dash-assets
(which would still be prefixed by custom route values -- which was a good move btw) then it seems unlikely that a user would need to modify this.
Just thinking about slowing the rate of kwarg growth for the constructor where possible, as it will get a but unwieldy at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point let's remove that, there's already much clutter in the kwargs. 👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, the fix to adding the routes prefix to the assets URL setting and getting looks good!
With the fixes to add better support for multi-route blueprints, I'm wondering if we could improve this some more.
One scenario that I could readily see happening when trying to support multiple Dash apps alongside each other using the same Flask server:
server.py
app1/app1.py
app2/assets/app1.css
app2/app2.py
app2/assets/app2.css
Where server.py defines a Flask instance and app1.py and app2.py both define Dash instances that pass in the Flask instance from the directory above.
app1's Dash instance might look like this:
app = dash.Dash(
server=server,
requests_pathname_prefix='/my-app1/',
routes_pathname_prefix='/my-app1/',
)
The assets for this app won't actually work however, as the default value of assets_folder
is derived from the cwd of the Flask instance. So it will automatically be set to assets
(ie at the same level as server.py. So instead the user will have to do:
app = dash.Dash(
server=server,
assets_folder="app1/assets",
requests_pathname_prefix='/my-app1/',
routes_pathname_prefix='/my-app1/',
)
There would be much less cognitive friction if the correct value of the assets path could be inferred as being relative to the Dash instance rather than the Flask instance. I guess this situation could be more generally described as when a Dash instance isn't found within the path that server.name
resolves to. Which, now that I think about it, might actually be a lot harder to make happen, so maybe this is a discussion for another time...
Here's the example app I was using to check this was working and find that issue with the static_folder value of the Blueplrint: https://github.com/ned2/dash-embed-recipes/tree/master/flask_multi It's has the same layout as in the example I mentioned above. |
Co-Authored-By: T4rk1n <[email protected]>
@ned2 Your examples are missing the Should we remove that or improve the logic here ? Line 105 in e72f483
|
Yeah, I didn't include the yep, so a potential change could be to remove that line overriding Are there any other places that would be affected by decoupling the Dash (also, if we did this, should it be in a separate PR?) |
I just tested the effect of removing that line that overwrites the If you think this won't have any other unwanted repercussions, then I'm happy to make that change. I'm also happy with how everything else is looking. 💃 |
Thanks @ned2, let's remove the line, I don't think it's useful. |
Fixed
Changed
assets_folder
argument now default to 'assets'name
argument, the default of__main__
will get thecwd
.Fixes #529