Need Help - Using Callbacks to update Bar Graph


#1

I am a newbie to Dash, I really find it awesome. Please will need help on how to use callbacks to update a simple bar graph. Data dose not reflect even when server runs.
Here is my code:

import dash
from dash.dependencies import Output, Event
import dash_core_components as dcc
import dash_html_components as html
import plotly
import plotly.graph_objs as go
from collections import deque
import pandas as pd

app = dash.Dash(__name__)

colors = {
    'background': '#111111',
    'background2': '#FF0',
    'text': '#7FDBFF'
}

app.layout = html.Div( children = [ 
        html.Div([
            html.H5('ANNx'),
            dcc.Graph(
                id='cx1'
                )

        ])
    ]
)


@app.callback(Output('cx1', 'figure'))
            #[Input('cxx', 'value')])
                #events=[Event('graph-update2', 'interval')])


def update_figure( ):
	return  {
                    'data': [
                        {'x': ['APC'], 'y': [9], 'type': 'bar', 'name': 'APC'},
                        {'x': ['PDP'], 'y': [8], 'type': 'bar', 'name': 'PDP'},
                    ],
                    'layout': {
                        'title': 'Basic Dash Example',
                        'plot_bgcolor': colors['background'],
                        'paper_bgcolor': colors['background']
                    }
                    }
	

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

#2

I think you are looking at outdated documentation, check this out to see how to use Interval component (I think Events don’t work anymore)

https://dash.plot.ly/live-updates


#3

You may not even need to use live updates. It’s incredibly difficult to tell what your inputs are intended to be so your current snippet contains a good number of flaws. The @app.callback NEEDS an Input AND and Output. I would recommend just looking at some more example snippets but @PSoriano is right, I’ve never seen Event since I’ve been using Dash, only Input, Output, and State.