@AnnMarieW Hi Ann, thanks for the suggestion. I modified the code to comment out the pages_plugin and it still gives me a keyerror even when I comment out the import pages_plugin (first try) and then commennt out the keyerror and the container (second try)
First try
Code:
import dash
import dash_bootstrap_components as dbc
# import pages_plugin
from dash import Dash, dcc, html
from dash_bootstrap_templates import ThemeChangerAIO
import dash_labs as dl
# load_figure_template("bootstrap")
dbc_css = (
"https://cdn.jsdelivr.net/gh/AnnMarieW/dash-bootstrap-templates@V1.0.1/dbc.min.css"
)
# app = Dash(__name__, plugins=[pages_plugin], external_stylesheets=[dbc.themes.BOOTSTRAP, dbc_css])
app = Dash(__name__, plugins=[dl.plugins.pages], external_stylesheets=[dbc.themes.BOOTSTRAP, dbc_css])
app.layout = dbc.Container(
html.Div([
html.H1('Manheim Capacity Model - Work in progress'),
html.H2('Updated as of 11/17/2021 by John Kang'),
dbc.Row(
[
dbc.Col(ThemeChangerAIO(aio_id="theme", radio_props={"value": dbc.themes.DARKLY}), width=2, ),
]
),
html.Div(
dcc.Link('Go back home', href=dash.page_registry['pages.home']['path'])
),
html.Div([
html.Div(dcc.Link(
f"{page['name']} - {page['path']}",
href=page['path']
))
for page in dash.page_registry.values()
if page['module'] != 'pages.not_found_404'
]),
pages_plugin.page_container
]),
className='dbc',
fluid=True
)
if __name__ == '__main__':
# app.run_server(debug=True)
app.run_server(debug=True, use_reloader=False, host="localhost", port=8007)
first try error:
Python 3.8.12 (default, Oct 12 2021, 03:01:40) [MSC v.1916 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.29.0 -- An enhanced Interactive Python. Type '?' for help.
PyDev console: using IPython 7.29.0
Python 3.8.12 (default, Oct 12 2021, 03:01:40) [MSC v.1916 64 bit (AMD64)] on win32
runfile('C:/Users/Jkang1/Cox Automotive/Recon Industrial Engineering Team - General/Capacity Model/main_python_files/app.py', wdir='C:/Users/Jkang1/Cox Automotive/Recon Industrial Engineering Team - General/Capacity Model/main_python_files')
Traceback (most recent call last):
File "C:\Anaconda3\envs\Capacity_venv\Lib\site-packages\IPython\core\interactiveshell.py", line 3444, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-a2b8dda0f18e>", line 1, in <module>
runfile('C:/Users/Jkang1/Cox Automotive/Recon Industrial Engineering Team - General/Capacity Model/main_python_files/app.py', wdir='C:/Users/Jkang1/Cox Automotive/Recon Industrial Engineering Team - General/Capacity Model/main_python_files')
File "C:\Program Files\JetBrains\PyCharm 2021.2.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2021.2.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/Jkang1/Cox Automotive/Recon Industrial Engineering Team - General/Capacity Model/main_python_files/app.py", line 27, in <module>
dcc.Link('Go back home', href=dash.page_registry['pages.home']['path'])
KeyError: 'pages.home' ```
I noticed that if I comment out the dcc.Link and the container (see code below) the dash app will run but will be in an error state:
Second try
import dash
import dash_bootstrap_components as dbc
# import pages_plugin
from dash import Dash, dcc, html
from dash_bootstrap_templates import ThemeChangerAIO
import dash_labs as dl
# load_figure_template("bootstrap")
dbc_css = (
"https://cdn.jsdelivr.net/gh/AnnMarieW/dash-bootstrap-templates@V1.0.1/dbc.min.css"
)
# app = Dash(__name__, plugins=[pages_plugin], external_stylesheets=[dbc.themes.BOOTSTRAP, dbc_css])
app = Dash(__name__, plugins=[dl.plugins.pages], external_stylesheets=[dbc.themes.BOOTSTRAP, dbc_css])
app.layout = dbc.Container(
html.Div([
html.H1('Manheim Capacity Model - Work in progress'),
html.H2('Updated as of 11/17/2021 by John Kang'),
dbc.Row(
[
dbc.Col(ThemeChangerAIO(aio_id="theme", radio_props={"value": dbc.themes.DARKLY}), width=2, ),
]
),
# html.Div(
# dcc.Link('Go back home', href=dash.page_registry['pages.home']['path'])
# ),
html.Div([
html.Div(dcc.Link(
f"{page['name']} - {page['path']}",
href=page['path']
))
for page in dash.page_registry.values()
if page['module'] != 'pages.not_found_404'
]),
# pages_plugin.page_container
]),
className='dbc',
fluid=True
)
if __name__ == '__main__':
# app.run_server(debug=True)
app.run_server(debug=True, use_reloader=False, host="localhost", port=8007)
The error I receive when I comment out the container (when I can load the app):
Second try error
⛑️
ID not found in layout
10:28:19 AM
Attempting to connect a callback Input item to component:
"_pages_plugin_location"
but no components with that id exist in the layout.
If you are assigning callbacks to components that are
generated by other callbacks (and therefore not in the
initial layout), you can suppress this exception by setting
`suppress_callback_exceptions=True`.
This ID was used in the callback(s) for Output(s):
_pages_plugin_dummy.children
_pages_plugin_content.children
_pages_plugin_content.children
My home.py code is standard:
import dash
from dash import html
dash.register_page(
__name__,
path='/',
name='Capacity Model homepage',
description='Welcome to my app',
order=0,
redirect_from=['/old-home-page', '/v2'],
extra_template_stuff='yup'
)
layout = html.Div([
html.H1('Homepage for the app'),
html.H2('Notes to be populated soon')
])type or paste code here```