-1

I have been trying to make visualizations using plotly dash and wanted to try out the first app example from the sites documentaion. I copied and pasted most of the code and made sure to make the correct indentations but seem to keep getting an error on the brackets. Any advice?

import dash
import dash_core_components as dcc
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

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': [4, 1, 2], 'type': 'bar', 'name':
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name':
            ],

            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    )
])

if __name__ == '__main__':
app.run_server(debug=True)
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141

1 Answers1

1

I have commented on the places where the brackets are not closed. Also, you are missing the values for "name". I have commented on it as well. P refers to parentheses (), C refers to curly brackets {} and S refers to square brackets [].

import dash
import dash_core_components as dcc
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div(children=[          #P1 open, S1 open
    html.H1(children='Hello Dash'),       # P2 open, P2 closed      
    
    html.Div(children='''                   
        Dash: A web application framework for Python.
    '''), # P3 open, P3 closed

    dcc.Graph(                                  #P4 open
        id='example-graph',         
        figure={                                #C1 open
            'data': [                           # S2 open
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name':# You are missing name parameter here;  Also C2 open; You are not closing this curly braces
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name':# You are missing name parameter here; Also C3 open; You are not closing this curly braces
            ], #S2 closed

            'layout': {                           #C4 open
                'title': 'Dash Data Visualization'
            }                                     # C4 closed
        } # C1 closed
    ) # P4 closed
])#S1 closed, P1 closed

if __name__ == '__main__':
    app.run_server(debug=True) # this need to be indented
Abhyuday Vaish
  • 2,357
  • 5
  • 11
  • 27