plotly / dash-labs

Work-in-progress technical previews of potential future Dash features.
MIT License
139 stars 39 forks source link

ModuleNotFoundError: No module named 'pages.' #113

Closed charmeem closed 2 years ago

charmeem commented 2 years ago

When trying to run the demo code of Chapter08-MultiPageDashApp I am getting this error. This error however doesn't generates if I include only histogram.py file in /pages folder. As I add other files like bar_charts.py this error appears.

Detail print out:

(base) c:\my_drive\python\dashboards\plotlydash\flaskdash1>python app.py
Traceback (most recent call last):
  File "app.py", line 6, in <module>
    app = dash.Dash(
  File "C:\Users\hp\anaconda3\lib\site-packages\dash\dash.py", line 420, in __init__
    plugin.plug(self)
  File "C:\Users\hp\anaconda3\lib\site-packages\dash_labs\plugins\pages.py", line 327, in plug
    _import_layouts_from_pages(pages_folder)
  File "C:\Users\hp\anaconda3\lib\site-packages\dash_labs\plugins\pages.py", line 301, in _import_layouts_from_pages
    page_module = importlib.import_module(f"pages.{page_filename}")
  File "C:\Users\hp\anaconda3\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pages.'
charmeem commented 2 years ago

This issue is resolved after upgrading dash to 2.5 and following suggestions in earlier issue#112

charmeem commented 2 years ago

However Now I am getting ' Duplicate callback Outputs' for every callback although there is no duplicate Output exits.

Error:

In the callback for output(s):
  histograms-graph.figure
Output 0 (histograms-graph.figure) is already in use.
Any given output can only have one callback that sets it.
To resolve this situation, try combining these into
one callback function, distinguishing the trigger
by using `dash.callback_context` if necessary.

histogram.py file:

from dash import Dash, dcc, html, Input, Output, callback
from dash import register_page
import plotly.express as px
import numpy as np

register_page(__name__)

np.random.seed(2020)

layout = html.Div(
    [
        dcc.Graph(id="istograms-graph"),
        html.P("Mean:"),
        dcc.Slider(
            id="histograms-mean", min=-3, max=3, value=0, marks={-3: "-3", 3: "3"}
        ),
        html.P("Standard Deviation:"),
        dcc.Slider(id="histograms-std", min=1, max=3, value=1, marks={1: "1", 3: "3"}),
    ]
)

@callback(
    Output("histograms-graph", "figure"),
    Input("histograms-mean", "value"),
    Input("histograms-std", "value"),
)
def display_color(mean, std):

    data = np.random.normal(mean, std, size=500)
    fig = px.histogram(data, nbins=30, range_x=[-10, 10])
    return fig
charmeem commented 2 years ago
import dash
import dash_bootstrap_components as dbc

app = dash.Dash(
    __name__, use_pages=True, external_stylesheets=[dbc.themes.BOOTSTRAP]
)

navbar = dbc.NavbarSimple(
    dbc.DropdownMenu(
        [
            dbc.DropdownMenuItem(page["name"], href=page["path"])
            for page in dash.page_registry.values()
            if page["module"] != "pages.not_found_404"
        ],
        nav=True,
        label="More Pages",
    ),
    brand="Multi Page App Plugin Demo",
    color="primary",
    dark=True,
    className="mb-2",
)

app.layout = dbc.Container(
    [navbar, dash.page_container],
    fluid=True,
)

if __name__ == "__main__":
    app.run_server(debug=True)
AnnMarieW commented 2 years ago

HI @charmeem Are you on Windows? If so, this is a bug and will be fixed in 2.5.1. The new release with the patch is coming soon.

charmeem commented 2 years ago

Yes I am using Windows. Will wait for the new release, thanks.

AnnMarieW commented 2 years ago

Hi @charmeem 5.1 was just released :confetti_ball:

Could you try running these multi-page sample apps and let me know how it goes?: https://github.com/AnnMarieW/dash-multi-page-app-demos

charmeem commented 2 years ago

Hello, I have just tried after upgrading to 2.5.1 , still seeing the same errors however with one improvement. I can see the pages in the navigation bar which was not the case before.

Secondly when I add a page 'heatmaps.py' in the /pages folder following error appears:

Exception Exception: modules ['pages..ipynb_checkpoints.heatmaps-checkpoint', 'pages.heatmaps'] have duplicate paths

Traceback (most recent call last) File "C:\Users\hp\anaconda3\Lib\site-packages\flask\app.py", line 2464, in call return self.wsgi_app(environ, start_response) File "C:\Users\hp\anaconda3\Lib\site-packages\flask\app.py", line 2450, in wsgi_app response = self.handle_exception(e) File "C:\Users\hp\anaconda3\Lib\site-packages\flask\app.py", line 1867, in handle_exception reraise(exc_type, exc_value, tb) File "C:\Users\hp\anaconda3\Lib\site-packages\flask_compat.py", line 39, in reraise raise value File "C:\Users\hp\anaconda3\Lib\site-packages\flask\app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "C:\Users\hp\anaconda3\Lib\site-packages\flask\app.py", line 1945, in full_dispatch_request self.try_trigger_before_first_request_functions() File "C:\Users\hp\anaconda3\Lib\site-packages\flask\app.py", line 1993, in try_trigger_before_first_request_functions func() File "C:\Users\hp\anaconda3\Lib\site-packages\dash\dash.py", line 2268, in router _validate.check_for_duplicate_pathnames(_pages.PAGE_REGISTRY) File "C:\Users\hp\anaconda3\Lib\site-packages\dash_validate.py", line 435, in check_for_duplicate_pathnames raise Exception(f"modules {modules} have duplicate paths")

charmeem commented 2 years ago

Capture

AnnMarieW commented 2 years ago

:thinking: So, you see these errors when you run one of the apps from the github repo I shared the link to previously?

AnnMarieW commented 2 years ago

can you share the code you are running? It looks like there might be conflicts between "Histogram" and "Histogram-checkpoint" for example

charmeem commented 2 years ago

wait

charmeem commented 2 years ago

Yes I am running codes in multi_page_example_1

charmeem commented 2 years ago

app.py

import dash
import dash_bootstrap_components as dbc

app = dash.Dash(
    __name__, use_pages=True, external_stylesheets=[dbc.themes.BOOTSTRAP]
)

navbar = dbc.NavbarSimple(
    dbc.DropdownMenu(
        [
            dbc.DropdownMenuItem(page["name"], href=page["path"])
            for page in dash.page_registry.values()
            if page["module"] != "pages.not_found_404"
        ],
        nav=True,
        label="More Pages",
    ),
    brand="Multi Page App Plugin Demo",
    color="primary",
    dark=True,
    className="mb-2",
)

app.layout = dbc.Container(
    [navbar, dash.page_container],
    fluid=True,
)

if __name__ == "__main__":
    app.run_server(debug=True)
AnnMarieW commented 2 years ago

This looks odd:

Exception: modules ['pages..ipynb_checkpoints.heatmaps-checkpoint', 'pages.heatmaps'] have duplicate paths

Do you know where 'pages..ipynb_checkpoints.heatmaps-checkpoint might be coming from?

charmeem commented 2 years ago

histogram.py

from dash import Dash, dcc, html, Input, Output, callback
from dash import register_page
import plotly.express as px
import numpy as np

register_page(__name__)

np.random.seed(2020)

layout = html.Div(
    [
        html.P("Mean:"),
        dcc.Slider(
            id="histograms-mean", min=-3, max=3, value=0, marks={-3: "-3", 3: "3"}
        ),
        html.P("Standard Deviation:"),
        dcc.Slider(id="histograms-std", min=1, max=3, value=1, marks={1: "1", 3: "3"}),
        dcc.Graph(id="histograms-graph"),
    ]
)

@callback(
    Output("histograms-graph", "figure"),
    Input("histograms-mean", "value"),
    Input("histograms-std", "value")    
)
def display_color(mean, std):

    data = np.random.normal(mean, std, size=500)
    fig = px.histogram(data, nbins=30, range_x=[-10, 10])
    return fig
charmeem commented 2 years ago

It is now working. ipynb_checkpoints was the directory automaticaly created by Jupyter note book. After removing that the code is wording fine.

Let me test with heatmaps.py page as well.

charmeem commented 2 years ago

All working now, Thanks for your hints.

AnnMarieW commented 2 years ago

oh, great - thanks! Now we'll know what to do for the next person who might have a similar issue :+1:

charmeem commented 2 years ago

Can I close the case?

AnnMarieW commented 2 years ago

yes, please

charmeem commented 2 years ago

OK, appreciate the work you are doing designing this wonderful product, keep it up !

Damistar05 commented 1 year ago

Hi. Please am trying to deploy my link to render. But am getting errors: dash.exceptions.NoLayoutException: The layout was None at the time that run_server was called. Make sure to set the layout attribute of your application before running the server

alexcjohnson commented 1 year ago

Hi @Damistar05 - If you can post your code and your question on https://community.plotly.com/ there are lots of folks who will be happy to help!

AnnMarieW commented 1 year ago

Hi @Damistar05 - please don't use this version - this was a prototype used to develop the Dash Pages feature and is no longer being maintained. This feature is now part of Dash :-)