Dash does not look in active directory?

Whenever I want to open a file, like a csv, that is right next to the dash script in the same directory, I get a “Not found” error, whereas the same file can be located if I put it instead in my home directory.

How can I force Dash to look in the active directory (that it is running from) when opening files?

Solution: What was actually wrong was that a subprocess call I was making from within Dash was not looking within the active directory, for some reason, even though I was able to make standard import function from function_file.py statements to import from other scripts within the active directory.

I fixed the problem by setting the cwd argument in subprocess.Popen to sys.path[0] (which is what Python’s import looks through), but I guess I need to learn more about how subprocess works.

A robust way to get the path to your Dash project is

import flask
path = flask.helpers.get_root_path(name)`

Where name is the same value passed in as the name parameter for your Dash app. This is how Dash itself finds out its path.

1 Like

Thanks a lot!! This will certainly help me in the future with Dash apps, and is better than using sys.path here.

1 Like