Hello, I 'm currently trying to add a footer into index_string and set some css for the whole app.
The local deployment is successful and working as it should. But on Heroku is does not load any css and js in assets folder at all. Googling a bit tells me that Heroku doesnt compile them(?). How to get through this?
Another question is about the app.index_string loads locally successfully but not showing on Heroku app as well.
I got several encoding errors while trying to run it, you should put # -*- coding: utf-8 -*- at the top of every file where you use strings that contains your language characters.
My problem was solve as you can see one the web. I never figure out why. Sometimes, it will update on heroku as similar to on my local. Sometimes it will not but no bug reported.
Philippe, you saved me from lots of headaches! I’ve spent the whole day trying to solve a problem where local resources (favicon, css, local images, as explained here) were being served automatically and successfully from assets folder in my local windows machine, but NOT in my linux server. By adding the __name__ inside the dash.Dash(__name__) it has been solved.
Do you know why this change solved the problem? What is doing the __name__ under the hood?
Thanks!
Just to understand it, why is it needed to add __name__ for using local resources in linux? I understand that the __name__ variable shows where the script is being run from, but why did it matter on my linux server (heroku)?
I’m data scientist so I still have a long software development learning path in front of me
It has nothing to do with linux, it’s how you run your application that make the difference. We use flask.helpers.get_root_path which take a module name to resolves the path to the module. By default, we have __main__ as the module name for a fallback that will work when the app is called by it’s module name (eg: python app.py).
When you run it thru some other command line (like the flask command or gunicorn/waitress) the __main__ module is no longer located where app.py is and now refer to some place like /venv/lib/site-packages/flask. Giving __name__ explicitly will always give the right path to the assets folder.
I was trying to load my css files from assets folder and it was not working because I run it from Flask CLI but it just worked when I included the name to the dash init. Thanks @Philippe for the answer. It would be great if this instruction is available in the dash tutorial page: https://dash.plot.ly/external-resources.
I am passing name into my Dash app creation and my assets are still not loading once the app is deployed with gunicorn.
I am using Dash 0.22 in both locations.
I create my Flask and Dash app like this:
app = Flask(name, static_url_path=’/static’, static_folder=static_folder, template_folder=template_folder)
dash_app = dash.Dash(name, server=app, url_base_pathname=’/dash’)
Am I doing something wrong with this part of my code?
What version should I update to? I was under the impression that 0.22 was the most recent version. Looking here: https://github.com/plotly/dash/releases. It looks like there isn’t a release between 0.19 and 0.26.5?
We didn’t tag releases until recently so they don’t appear in the github releases. You can look at the changelogs for a complete list of all the changes.