I needa step by step guidance how to set-up Dash’s Asset folder to work in Django.
I know it’s much to ask but if somebody have a solution to share - I need it.
It can be just an example of working solution of course.
I spent couple days trying to make it work and I can not. I tried many variants.
Alternatives are use of CDN - didn’t try that, but see no reason it wont work (but I’d prefer servicing locally)
or to embed styling in-line into Dash code (which is not a viable option).
Lately I focused on development state of Django only, so, no ‘collectstatic’ - it was just to narrow scope of possible errors.
I did spend time on documentation and any examples I could find (none address Assets file) and I still can’t figure it out. I see other people had the same problem before and wonder if they found a workable solution.
In summary: what do I need to do have css dash file working locally in django project?
Did you work through the local assets part of the documentation? Its not the clearest exposition - a step-by-step guide would be helpful - but it does cover the needed settings.
Yes, I did. I also used code from examples for my tests to make sure I didn’t miss anything or commit any typo.
Can’t be100% sure that I didn’t make any mistake though.
My dash app - very simple test, almost copy of the one from example nr 1 + styling with css - works fine when alone. Adding dash-css to django I can not succeed.
Maybe I need few days off the problem and try again. Would be ensuring if I see a working code somewhere. Maybe it’s a good idea to add example nr 11 with passing of css from assets to django…
There is an outstanding issue re documentation #235 - however some of the discussion of issues around it might help.
An alternative, given it is just CSS, would be to use the
external_stylesheets argument; this would be css at the server (rather than per-dash-app) level.
Yes, that should work.
Not sure if I want to use this rout. Locally I can start simple server to provide this css file but deployment can be bit complicated. Better is to use some web url from getgo. My goal is to use local sources though, both in development and deployment.
Maybe there is a way to include css directly in myapp.py file but I suspect it take a lot of work and alterating dash’s package code. I tried external_stylesheets from local file and it didn’t work.
If I wont find a solution I see what I can do with authentication to dash and, maybe, serve this app from different server independently from django.
If you’re already running Django, then surely you could set
external_stylesheets to be something served by it. You would have to put it into something like a django app’s static files in order for Django to find it. This would also be a lot more cache (both server and browser) friendly than trying to serve it relative to the Dash app endpoint.
Are you in a position to post more details regarding the
external_stylesheets approach not working? That doesn’t sound right.
I’m pretty new to django, I tried static from different locations and it didn’t work.
As per external_sheets, I said I did not try to serve css from web location. I was unsuccessful to use local file as css source for dash (except assets folder ofc).
My testing code is available for anybody wishes to look at it. I don’t want to post it here as it is a lot of files. I also do not have gitHub. I can zip the whole project and email it.
It might be worthwhile reviewing how Django serves static files in general. Something like this Django tutorial might help in locating useful parts of the documentation.
Dash’e css code needs to be placed in dash’s app code. Placing it in Django template directly or via static, does not work (at least not for me) - in this approach css affects all django’s html but not Dashes’s html.
At this point I decided to structure my project differently and serve Dash dashboard outside Django. I will yet consider serving css via cdn or maybe from separate docker server.
If I have some spare time in the future I may dig in more into this problem.
Thanks for all responses.