I’ve built a plotly multi-page app in python and it works proper in the python only environment. The core concept of is to register pages in sub modules as pages.
The standard structure of this is:
- app.py
- pages
|-- page_1.py
|-- page_2.py
|-- page_3.py
- assets
|-- my.css
The initialization of the code per page is like that:
import dash
from dash import html, dash_table
import dash_bootstrap_components as dbc
dash.register_page(__name__, path='/', name='Page-1', order=0)
layout = html.Div()
In the Python environment this code is executed during the initialization phase. But if I compile it via cx_freeze int a win executable it is not.
My cx_freeze setup.py is as followed:
options = {
'build_exe': {
'include_files': ['config.json', 'src/assets/'],
'includes': [
'cx_Logging', 'idna'
],
'packages': [
'asyncio', 'flask', 'dash', 'plotly', 'waitress', 'src'
]
}
}
base = 'console'
executables = [
Executable('main.py', base=base, target_name=myexe)
]
setup(name= myexe,
packages=find_packages(),
version='0.1',
description='None,
options=options,
executables=executables
)
Because I am a beginner in Python, I spend several days to figure out what is happening. Know it is clear, I receive a page 404 error because the initialization is never executed.
I tried to encapulate the initilalization code in a function and called this function by my self. But the plotly framework throws an excetion
dash.exceptions.PageError: `dash.register_page()` must be called after app instantiation
So this seems not to solve my problem.
Thx, for help
TobiJoppe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.