Black Lives Matter. Please consider donating to Black Girls Code today.
Dash Enterprise delivers an incredible 21x cost savings 💸Download the e-book!

Graphs not reloading with new data on page reload

Hi,
I want to redraw my graphs on page reload, in below graphs you can see one of the graphs(id=g1) data is created using random values. I want my graphs to get reloaded with new data on every page load.
I don’t want to use any live updated and also all the graphs must be inside html.Div( … )
Please help me!!

import dash
import dash_html_components as html
import dash_core_components as dcc
import random
app = dash.Dash()
app.layout = html.Div([
    html.Div([
        html.Div([
            html.H3('Column 1'),
            dcc.Graph(id='g1', figure={'data': [{'y': [ random.randint(0,100) for val in range(10)]}]})
        ], className="six columns"),

        html.Div([
            html.H3('Column 2'),
            dcc.Graph(id='g2', figure={'data': [{'y': [1, 2, 3]}]})
        ], className="six columns"),
    ], className="row"),

])

app.css.append_css({
    'external_url': 'https://codepen.io/chriddyp/pen/bWLwgP.css'
})

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

I also want to know is there anyway to turn off option for loading date from plotly app memory once server started.

See https://plot.ly/dash/live-updates, in particular the section on “Updates on Page Load”.

I’m not quite sure what you mean here. Could you create a new thread and a simple example to show what you mean? Thanks!

Thank you!!
I followed https://plot.ly/dash/live-updates

I have modified my script to this and its working.

import dash
import dash_html_components as html
import dash_core_components as dcc
import random
app = dash.Dash()

app.css.append_css({
    'external_url': 'https://codepen.io/chriddyp/pen/bWLwgP.css'
})

def serve_layout():
    return html.Div([
    html.Div([
        html.Div([
            html.H3('Column 1'),
            dcc.Graph(id='g1', figure={'data': [{'y': [ random.randint(0,100) for val in range(10)]}]})
        ], className="six columns"),

        html.Div([
            html.H3('Column 2'),
            dcc.Graph(id='g2', figure={'data': [{'y': [1, 2, 3]}]})
        ], className="six columns"),
    ], className="row"),

])
app.layout = serve_layout

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

Now every time I reload the page, I can see my graph plotting new data.
Thanks again!!