Dash Pages -- ignore hidden files and folders

If I use jupyterlab for my text editor, it creates some cache files like pages/.ipynb_checkpoints/my_page.py. When dash scans the pages directory for .py files, these get included, resulting in Duplicate Callback errors. I imagine similar things can happen with other text editors too.

Is there an easy way to exclude hidden files and folders from the scan?

Hi @chubukov

What version of Dash are you using? This was fixed in one of the more recent version.

While I think hidden files should just be excluded by default, maybe this is the right time to suggest allowing some even more flexible structure instead of forcing the pages directory.

from glob import glob
my_pages=glob('pages/**/*.py',recursive=True) 
app= dash.Dash(use_pages=my_pages)

Hm, I just upgraded to 2.6.1

@chubukov

You can set a folder other than “pages/” if you like by setting

app = Dash(__name__, pages_folder="/my_pages_folder")

It does search for .py files recursively, so it’s possible to have nested folders. It does also exclude files that start with a period or an underscore. Not sure why this isn’t working for you. Are you using JupyterDash ?

Cool, I didn’t know this, thanks.

In this case the containing folder starts with a dot, not the file name itself. Could that be the difference?

oh! That’s this issue! :male_detective:

It’s only excluding the files, not the folders that start with a period. Mystery solved!! Thanks, that should be an easy fix.

@chubukov The pull request has been submitted - thanks for reporting and identifying the issue. :slight_smile:

1 Like