Search code examples
pythondockerfilegunicornplotly-dashgoogle-cloud-run

Dash app cannot find pages folder when deploying on GCP using gunicorn


I am trying to deploy my dash app which uses dash_extensions, Dash_proxy and has multiple pages in the pages folder on GCP cloud run using gunicorn but the app cannot find the pages folder. It works perfectly fine when I use the development server but breaks in the production server because it cannot find the folder path.

The app (following code is inside the app.py file):

app = DashProxy(use_pages=True, pages_folder=pages_folder, external_stylesheets=[dbc.themes.SIMPLEX])

The app.py file and the pages folder are in the same directory

I have tried tried to following methods to get the folder path:

pages_folder="pages"
pages_folder=os.path.join(os.path.dirname(__file__), "pages")
for p in Path('.').rglob('*'):
    if str(p).endswith('pages'):
        pages_folder = str(p)
        break

None of the above three work in when deploying on gcp using gunicorn through docker:

Dockerfile command:

CMD ["gunicorn"  , "-b", "0.0.0.0:8000", "app:server"]

enter image description here

But if I use dev server through docker like following code it works:

CMD python app.py

Does anyone have any ideas of how to make it work with gunicorn?

Thanks for the help!

-Rexon


Solution

  • Yes I did. Just had to specify the root folder. This is what I did and it seems to work for me.

    pages_folder=os.path.join(os.path.dirname(__name__), "pages")
    
    app = DashProxy(__name__,use_pages=True, pages_folder=pages_folder, external_stylesheets=[dbc.themes.SIMPLEX])
    
    server=app.server