Graph Callback Exeption

Hi guys,

I’m trying to, in advance, write a really simple code with callbacks, but not yet.

The code is pretty but useless. I have this elocuency exception from Dash:

TypeError: Cannot read property ‘data’ of null

  • Imports:
import dash
import dash_auth
import dash_html_components as html
import plotly.graph_objs as go
import dash_bootstrap_components as dbc
  • App
app = dash.Dash(__name__,
                external_stylesheets = external_stylesheets)

app.layout = html.Div([navbar, tablas, graficos, graph_selldata])

server = app.server
if __name__ == '__main__':
    app.run_server(debug = True)
  • Database
...
df_contacts = pd.read_sql_query(query_contacts, conn)
df_studies = pd.read_sql_query(query_studies, conn)
df_operations = pd.read_sql_query(query_operations, conn)
...
  • Graphs and Dropdown
graph_selldata = dbc.Container([
    dcc.Dropdown(
        id = 'selldropdown',
        options = [
            {'label': 'Observador de meteorología', 'value': 'OBS'},
            {'label': 'Curso básico climatología', 'value': 'CBC'}

        ],
        value = 'Todos los cursos'
    ),
    dcc.Graph(id = 'sellgraph')
])
  • Callbacks
@app.callback(
    dash.dependencies.Output('sellgraph', 'figure'),
    [dash.dependencies.Input('selldropdown', 'value')])
def update_output(value):
    if value == 'OBS':
        figure = {
            'data': [
                {
                    'x': df_operations['date'], #Column of de database table 'date'
                    'y': df_operations['countobservador'] #Column of de database table 'countobservador'
                }
            ]
        }
        return figure
    elif value == 'CBC':
        figure = {
            'data': [
                {
                    'x': df_operations['date'],
                    'y': df_operations['countbasico']
                }
            ]
        }
        return figure

I’m trying tu update the graph data with a Dropdown but…This. The problem is with de JavaSript but i can’t recognize the cause of the problem.

With simple Graph i not have a problem but if i entry this callback…you see.

Thanks for your time,

Cristian