Plotly Dash Error loading layout

Question:

Hi I am new to Dash and I was following the tutorial on the page https://dash.plot.ly/getting-started I got an error citing msgpack not installed. I installed it later and then ran the following code given on the page.

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A Web Application framework for Python.
        '''),

    dcc.Graph(
        id='example-graph',
        figure={
            'data':[
                {'x':[1,2,3],'y':[2,4,1],'type':'bar','name':'SF'}
            ],
            'layout': {
                'title':'Dash Data Visualisation'
            }
        }
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)

When I go on this http://127.0.0.1:8050/ I get the following error

Error loading layout

I read the dash documentation and community help, there are some similar questions asked, but I am not able to understand them. Please help.

Asked By: user9149054

||

Answers:

The code worked fine when I ran it in terminal. The link showed a bar plot (below). May be your dash installation has some missing libraries / requirement files. You could try doing either pip install or conda install the pacakges listed below from terminal.

Example on how to install using pip

$ pip install <package name here>

or if using Ananconda

$ conda install <package name here>

example:

$ pip install chardet==3.0.4

Packages

chardet==3.0.4
click==6.7
Cython==0.28.2
dash==0.21.0
dash-core-components==0.22.1
dash-html-components==0.10.0
dash-renderer==0.12.1
decorator==4.3.0
nbformat==4.4.0
numpy==1.14.2
pandas==0.22.0
pandas-datareader==0.6.0
plotly==2.5.1
python-dateutil==2.7.2
pytz==2018.4
requests==2.18.4
urllib3==1.22
Werkzeug==0.14.1

enter image description here

Edit – 1 …………………………………..

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()
app.layout = html.Div(children=[html.H1(children='Hello Dash')])
if __name__ == '__main__':
    app.run_server(debug=True)

Based on the post add the line below to import.

import dash
import dash_core_components as dcc
import dash_html_components as html
from dashapp import app as application

app = dash.Dash()
app.layout = html.Div(children=[html.H1(children='Hello Dash')])
if __name__ == '__main__':
    app.run_server(debug=True)

or

import dash
import dash_core_components as dcc
import dash_html_components as html
from dashapp import server as application

app = dash.Dash()
app.layout = html.Div(children=[html.H1(children='Hello Dash')])
if __name__ == '__main__':
    app.run_server(debug=True)

or

import dash
import dash_core_components as dcc
import dash_html_components as html
from dashapp import server as application

app = dash.Dash()
app.layout = html.Div(children=[html.H1(children='Hello Dash')])
if __name__ == '__main__':
    app.run_server(debug=True)

from dashapp import server as application

and/or change either of the following [post]:

app = Dash()
app = dash.Dash(__name__)
server = app.server

Edit – 2 …………………………………..

Install dash libraries

pip install dash==0.21.1  # The core dash backend
pip install dash-renderer==0.13.0  # The dash front-end
pip install dash-html-components==0.11.0  # HTML components
pip install dash-core-components==0.24.0  # Supercharged components
pip install plotly --upgrade  # Latest Plotly graphing library

and also

pip install dash.ly --upgrade
Answered By: Nilesh Ingle

I once again deleted all libraries and reinstalled them and also ran the code in Chrome. It is working fine now.

Answered By: user9149054

I am new to Dash as well and in my case, there was a problem with syntax.

I was doing this :

app.layout = html.Div({

and was getting the "Error Loading Layout"

But when I switched to this:

app.layout = html.Div(children=[

The error vanished.

Check the syntax of the main Div for any errors.

Answered By: Sahil Basera

You get the same error when you are using dash in older shinyproxy versions. As the search will redirect you to this post I place that answer also here.

use

app.config.update({
'routes_pathname_prefix': os.environ['SHINYPROXY_PUBLIC_PATH'],
'requests_pathname_prefix': os.environ['SHINYPROXY_PUBLIC_PATH']
})

as shown here and discussed here

Answered By: horseshoe

Just set debug=False and check your logs

Answered By: Vincent Agnes
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.