"Error loading layout" even though code worked the first time

Hi,

I am new to Dash and I started with a tutorial from this webpage: Develop Data Visualization Interfaces in Python With Dash – Real Python

Below is the full code I ran, a copy-paste of what was in the website:

import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import numpy as np
from dash.dependencies import Output, Input

data = pd.read_csv("avocado.csv")
data["Date"] = pd.to_datetime(data["Date"], format="%Y-%m-%d")
data.sort_values("Date", inplace=True)

external_stylesheets = [
    {
        "href": "https://fonts.googleapis.com/css2?"
        "family=Lato:wght@400;700&display=swap",
        "rel": "stylesheet",
    },
]
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.title = "Avocado Analytics: Understand Your Avocados!"

app.layout = html.Div(
    children=[
        html.Div(
            children=[
                html.P(children="🥑", className="header-emoji"),
                html.H1(
                    children="Avocado Analytics", className="header-title"
                ),
                html.P(
                    children="Analyze the behavior of avocado prices"
                    " and the number of avocados sold in the US"
                    " between 2015 and 2018",
                    className="header-description",
                ),
            ],
            className="header",
        ),
        html.Div(
            children=[
                html.Div(
                    children=[
                        html.Div(children="Region", className="menu-title"),
                        dcc.Dropdown(
                            id="region-filter",
                            options=[
                                {"label": region, "value": region}
                                for region in np.sort(data.region.unique())
                            ],
                            value="Albany",
                            clearable=False,
                            className="dropdown",
                        ),
                    ]
                ),
                html.Div(
                    children=[
                        html.Div(children="Type", className="menu-title"),
                        dcc.Dropdown(
                            id="type-filter",
                            options=[
                                {"label": avocado_type, "value": avocado_type}
                                for avocado_type in data.type.unique()
                            ],
                            value="organic",
                            clearable=False,
                            searchable=False,
                            className="dropdown",
                        ),
                    ],
                ),
                html.Div(
                    children=[
                        html.Div(
                            children="Date Range",
                            className="menu-title"
                            ),
                        dcc.DatePickerRange(
                            id="date-range",
                            min_date_allowed=data.Date.min().date(),
                            max_date_allowed=data.Date.max().date(),
                            start_date=data.Date.min().date(),
                            end_date=data.Date.max().date(),
                        ),
                    ]
                ),
            ],
            className="menu",
        ),
        html.Div(
            children=[
                html.Div(
                    children=dcc.Graph(
                        id="price-chart", config={"displayModeBar": False},
                    ),
                    className="card",
                ),
                html.Div(
                    children=dcc.Graph(
                        id="volume-chart", config={"displayModeBar": False},
                    ),
                    className="card",
                ),
            ],
            className="wrapper",
        ),
    ]
)


@app.callback(
    [Output("price-chart", "figure"), Output("volume-chart", "figure")],
    [
        Input("region-filter", "value"),
        Input("type-filter", "value"),
        Input("date-range", "start_date"),
        Input("date-range", "end_date"),
    ],
)
def update_charts(region, avocado_type, start_date, end_date):
    mask = (
        (data.region == region)
        & (data.type == avocado_type)
        & (data.Date >= start_date)
        & (data.Date <= end_date)
    )
    
    #print(mask)
    
    filtered_data = data.loc[mask, :]
    price_chart_figure = {
        "data": [
            {
                "x": filtered_data["Date"],
                "y": filtered_data["AveragePrice"],
                "type": "lines",
                "hovertemplate": "$%{y:.2f}<extra></extra>",
            },
        ],
        "layout": {
            "title": {
                "text": "Average Price of Avocados",
                "x": 0.05,
                "xanchor": "left",
            },
            "xaxis": {"fixedrange": True},
            "yaxis": {"tickprefix": "$", "fixedrange": True},
            "colorway": ["#17B897"],
        },
    }

    volume_chart_figure = {
        "data": [
            {
                "x": filtered_data["Date"],
                "y": filtered_data["Total Volume"],
                "type": "lines",
            },
        ],
        "layout": {
            "title": {"text": "Avocados Sold", "x": 0.05, "xanchor": "left"},
            "xaxis": {"fixedrange": True},
            "yaxis": {"fixedrange": True},
            "colorway": ["#E12D39"],
        },
    }
    return price_chart_figure, volume_chart_figure


if __name__ == "__main__":
    app.run_server(debug=False)

It worked amazing when I first worked on it. I then proceeded to close everything and didn’t work on it for a few days. When I came back after a few days and ran the exact same code, I get “Error loading layout”.

After Googling for awhile, I noticed that there could be multiple causes for that error. I tried clearing browser cache and cookies and tried different browsers but with no success.

I think my last resort is to delete and reinstall my virtual environment but that seems like a short term solution since it will be pretty weird reinstalling my virtual environment every time this happens.

Any help in resolving this issue is appreciated! The block below contains the list of packages in my conda virtual environment.

Thanks.

# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: win-64
backcall=0.2.0=pyhd3eb1b0_0
backports=1.0=pyhd3eb1b0_2
backports.functools_lru_cache=1.6.4=pyhd8ed1ab_0
blas=1.0=mkl
bottleneck=1.3.2=py39h7cc1a96_1
brotlipy=0.7.0=py39h2bbff1b_1003
ca-certificates=2021.9.30=haa95532_1
certifi=2021.10.8=py39haa95532_0
cffi=1.14.6=py39h2bbff1b_0
click=8.0.1=pyhd3eb1b0_0
cloudpickle=2.0.0=pyhd3eb1b0_0
colorama=0.4.4=pyhd3eb1b0_0
dash=1.19.0=pyhd3eb1b0_0
dash-core-components=1.3.1=py_0
dash-html-components=1.0.1=py_0
dash-renderer=1.1.2=py_0
dash-table=4.4.1=pyhd3eb1b0_0
dataclasses=0.8=pyh6d0b6a4_7
debugpy=1.4.1=py39hd77b12b_0
decorator=5.1.0=pyhd3eb1b0_0
entrypoints=0.3=py39haa95532_0
et_xmlfile=1.1.0=py39haa95532_0
flask=2.0.2=pyhd3eb1b0_0
flask-compress=1.5.0=py_0
future=0.18.2=py39haa95532_1
importlib-metadata=4.8.1=py39haa95532_0
intel-openmp=2021.3.0=haa95532_3372
ipykernel=6.4.1=py39haa95532_1
ipython=7.28.0=py39h832f523_0
ipython_genutils=0.2.0=pyhd3eb1b0_1
itsdangerous=2.0.1=pyhd3eb1b0_0
jdcal=1.4.1=pyhd3eb1b0_0
jedi=0.18.0=py39hcbf5309_2
jinja2=3.0.1=pyhd3eb1b0_0
jupyter_client=7.0.1=pyhd3eb1b0_0
jupyter_core=4.8.1=py39haa95532_0
libsodium=1.0.18=h8d14728_1
markupsafe=2.0.1=py39h2bbff1b_0
matplotlib-inline=0.1.3=pyhd8ed1ab_0
mkl=2021.3.0=haa95532_524
mkl-service=2.4.0=py39h2bbff1b_0
mkl_fft=1.3.1=py39h277e83a_0
mkl_random=1.2.2=py39hf11a4ad_0
nest-asyncio=1.5.1=pyhd3eb1b0_0
numexpr=2.7.3=py39hb80d3ca_1
numpy=1.21.2=py39hfca59bb_0
numpy-base=1.21.2=py39h0829f74_0
openpyxl=3.0.5=py_0
openssl=1.1.1l=h8ffe710_0
pandas=1.3.3=py39h6214cd6_0
parso=0.8.2=pyhd3eb1b0_0
pickleshare=0.7.5=pyhd3eb1b0_1003
pip=21.2.4=py39haa95532_0
plotly=5.1.0=pyhd3eb1b0_0
prompt-toolkit=3.0.20=pyhd3eb1b0_0
pycparser=2.20=py_2
pygments=2.10.0=pyhd3eb1b0_0
python=3.9.7=h6244533_1
python-dateutil=2.8.2=pyhd3eb1b0_0
python_abi=3.9=2_cp39
pytz=2021.3=pyhd3eb1b0_0
pywin32=301=py39hb82d6ee_0
pyyaml=5.4.1=py39h2bbff1b_1
pyzmq=22.3.0=py39he46f08e_0
setuptools=58.0.4=py39haa95532_0
six=1.15.0=py39haa95532_0
spyder-kernels=2.0.5=py39haa95532_0
sqlite=3.36.0=h2bbff1b_0
tenacity=8.0.1=py39haa95532_0
tornado=6.1=py39hb82d6ee_1
traitlets=5.1.0=pyhd3eb1b0_0
tzdata=2021a=h5d7bf9c_0
vc=14.2=h21ff451_1
vs2015_runtime=14.27.29016=h5e58377_2
wcwidth=0.2.5=pyh9f0ad1d_2
werkzeug=2.0.1=pyhd3eb1b0_0
wheel=0.37.0=pyhd3eb1b0_1
wincertstore=0.2=py39haa95532_2
yaml=0.2.5=he774522_0
zeromq=4.3.4=h0e60522_1
zipp=3.6.0=pyhd3eb1b0_0