cx_freeze include css file and image in dash app

Viewed 425

I have some difficulties to apply a css file to my dash app when using cx_freeze. If I run python app.py the layout is properly applied, however not if I am executing the .exe generated by cx_freeze. Then the default html layout is displayed. The css and the image appear in the same directory where the .exe is located.

This is how my setup.py looks like.

from setuptools import find_packages
from cx_Freeze import setup, Executable


options = {
    'build_exe': {
        'includes': [
            'cx_Logging', 'idna', 'idna.idnadata'
        ],
        'packages': [
            'asyncio', 'flask', 'jinja2', 'dash', 'plotly', 'waitress'
        ],
        'excludes': ['tkinter'],
        'include_files': [
          'assets/logo.jpg', 'assets/style.css'
        ],
    }
}

executables = [
    Executable('server.py',
               base='console',
               targetName='dash_app.exe')
]

setup(
    name='BI_Report',
    packages=find_packages(),
    version='0.0.1',
    description='rig',
    executables=executables,
    options=options
)

To load the external files I use a helper function as suggested here:

def find_data_file(filename):
    if getattr(sys, 'frozen', False):
        # The application is frozen
        datadir = os.path.dirname(sys.executable)
    else:
        # The application is not frozen
        # Change this bit to match where you store your data files:
        datadir = os.path.dirname(__file__)

    return os.path.join(datadir, filename)


app = dash.Dash(__name__,
                assets_folder=find_data_file('assets/'))

I am using:

Python 3.7.6
dash 1.9.1
cx-freeze 6.1

Any help much appreciated!

0 Answers
Related