I have divided my dash app in several source files, including .py files but also .css and .js files.
The dash server only watches for changes in the app.py file, but I would like it watched for any file updates I tell it to watch.
How can I accomplish that?
I’m very confident that this could be done.
Dash uses Flask under the hood, including Flask’s reloader. I’d recommend searching for info about Flasks’s reloader or GitHub issues for Flask’s reloader.
If you find out more, please update the issue!
I wasn’t sure if the watching file feature was made by Flask, or some other magic library.
I’ll take a closer look to it and share my results here.
The reloading behavior is associated with the running of an app, so is a feature of the Flask development server (and more specifically, is enabled with through the
debug flag), as opposed to a Flask app in-and-of itself. If you are using another WSGI server for running your app, then it will likely have this feature also which you may need to enable explicitly. For instance, gunicorn has a
Now would also be a good time to mention that when using the Flask development server, the Flask docs don’t recommend using the
Flask.run() method (which the Dash docs use) if you want reliable auto-code reloading. Instead they recommend running
flask run from the command line and specifying the location of the WSGI callable (eg
app.server for Dash) the command line.
In general, these methods only work for Python files that your app imports. However you don’t actually need the server to reload your CSS and JS files, as Flask just directs requests for these to the files on the file systems (assuming you’re using Flask to serve static assets), serving whatever the current version is. The one caveat here is that browsers can aggressively cache static assets. So to ensure you get the current version, you can bypass the cache by hitting CTRL+F5.
Wow, thank you very much @nedned. I was using Dash without the debug flag set.
I’ve just set it and it works! I’ll do a more deep testing with all the dependencies and let you know if I miss some autoreload when modifying source files.