Attribute Error: layout traverse

I am new to plotly/Dash. When I run the code from the website tutorial Updates On Page Load,

import datetime

import dash
import dash_html_components as html

def serve_layout():
    return html.H1('The time is: ' + str(datetime.datetime.now()))

app = dash.Dash()
app.layout = serve_layout

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

I get the following error

for component in self.layout.traverse():
AttributeError: ‘function’ object has no attribute ‘traverse’

However if I do app.layout = serve_layout() then it works.

I searched the forum and found some discussion about redefining the app twice, but nothing regarding ‘function’ object. Any help is much appreciated.

Thanks a lot

Could you try upgrading dash? There have been a few bugfixes about this lately.

Thanks for the suggestion. Dash seems to be up to date 0.26.0, I upgraded the components nevertheless. But still same issue.

plotly 3.1.1
core components 0.27.2
dash renderer 0.13.2
html components 0.11.0

Hi ddas!

Thanks for the report. This was an issue in the dash core library: https://github.com/plotly/dash/issues/334.

A fix for this was just released in dash==0.26.1. I tested this app and it should work, but let us know if you have any more problems with this example!

Best,
Ryan

1 Like

thank you so much, it works now. Really appreciate this and the quick turnaround. many thanks.

1 Like

I am also observing this with the above example shown. Here are my dash versions as shown in my Pipfile:

dash = “==0.26.2”
dash-html-components = “==0.11.0”
dash-core-components = “==0.28.0”
dash-renderer = “==0.13.1”
plotly = “*”

Looks like this (https://github.com/plotly/dash/pull/336) is working with:
dash==0.26.3
dash-core-components==0.27.2

1 Like

Thanks, works like a charm!

Thanks, yes this is the solution. You do not need dash-core-components==0.27.2 though.

Thanks @rnarren1 There was a comment in the PR discussion about an issue with dash-core-components==0.28.0 - not sure if that has been resolved, yet, but it probably doesn’t apply to this specific issue.