# First update of plotly Dash with live update

**URL:** <https://community.plotly.com/t/first-update-of-plotly-dash-with-live-update/6108>\
**Category:** Dash Python\
**Created:** [October 5, 2017, 1:14pm UTC](https://community.plotly.com/t/first-update-of-plotly-dash-with-live-update/6108 "2017-10-05T13:14:26Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)\
**Post date:** [October 6, 2017, 3:09am UTC](https://community.plotly.com/t/first-update-of-plotly-dash-with-live-update/6108/2 "2017-10-06T03:09:05Z")

</div>

Check out the solution in [Trigger an event by changing tab](https://community.plotly.com/t/trigger-an-event-by-changing-tab/5987/9?u=chriddyp). In short, you’ll need to call `gen_plot()` from inside `serve_layout` to get the most recent figure. In order to call `gen_plot`, you’ll need to remove the decorator from it.

Here is your example with those changes:

```auto
import dash
import pandas as pd
import plotly.graph_objs as go
import dash.dependencies as ddp
import dash_core_components as dcc
import dash_html_components as html

def plot_figure(data):
    layout = dict(
    title="Figure w/ plotly",
    )

    fig = dict(data=data, layout=layout)
    return fig

def serve_layout():
    return html.Div(children=[
        html.Div([
            html.H1("Plotly test with Live update",
                    style={"font-family": "Helvetica",
                           "border-bottom": "1px #000000 solid"}),
            ], className='banner'),
        html.Div([dcc.Graph(id='plot')],),
        dcc.Interval(id='live-update', interval=interval),
],)

second = 1000
minute = 60
hour = 60
day = 24
interval = 1/2*day*hour*minute*second

app = dash.Dash()

app.layout = serve_layout

def gen_plot():
    ind = ['a', 'b', 'c', 'd']
    df = pd.DataFrame({'one' : pd.Series([4., 3., 2., 1.], index=ind),
                       'two' : pd.Series([1., 2., 3., 4.], index=ind)})

    trace = [go.Scatter(x=df.index, y=df['one'])]
    fig = plot_figure(trace)
    return fig

app.callback(
    ddp.Output('plot', 'figure'),
    [],
    [],
    [ddp.Event('live-update', 'interval')])(gen_plot)

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

```

I recommend reading through [https://stackoverflow.com/questions/739654/how-to-make-a-chain-of-function-decorators/1594484#1594484](https://stackoverflow.com/questions/739654/how-to-make-a-chain-of-function-decorators/1594484#1594484) to get a better sense of how these decorators work and how you can refactor your code around them. 🍻

---

_[View the full topic](https://community.plotly.com/t/first-update-of-plotly-dash-with-live-update/6108)._
