# Update graphs drawn from an sql query?

**URL:** <https://community.plotly.com/t/update-graphs-drawn-from-an-sql-query/67291>\
**Category:** Dash Python\
**Tags:** question\
**Created:** [August 24, 2022, 8:25am UTC](https://community.plotly.com/t/update-graphs-drawn-from-an-sql-query/67291 "2022-08-24T08:25:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BeginnerDash](https://avatars.discourse-cdn.com/v4/letter/b/53a042/32.png) [@BeginnerDash](https://community.plotly.com/u/BeginnerDash)\
**Post date:** [August 24, 2022, 8:25am UTC](https://community.plotly.com/t/update-graphs-drawn-from-an-sql-query/67291/1 "2022-08-24T08:25:16Z")

</div>

I have a dashboad with two parts, part 1 and part 2.

![dashboardd](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/2/b/2bd3ef367e14aca9faabd045954c2e439ac38093.png)

The part 1 gets its data from a SQL query. What I want is to update it every 8 hours. The part 2 contains another python function (displaying text from an imported file) that I would want to update every 10 minutes.

I am mostly concerned by the part 1 at the moment, I looked at the “Live Updates” section of the site, and I believe the dcc.Interval component might be interesting to do it. But I don’t know if it will relaunch the query every time it gets updated ?

But it doesn’t work, I get the message

> “An object was provided as `children` instead of a component, string, or number (or list of those)”

I also wonder, if I put multiple graphs in the Part 1, will it update all of them regularly ?

**Here is the html**

```
app.layout = html.Div(
className='dashboard',
style={"display":"flex","border":"1px black solid", 'width':'100%','height':'97vh'},
children=[

    # Refresh every 5s
   dcc.Interval(
   id='interval-component',
   interval=5000, # in milliseconds
    n_intervals=0
   ),

    # Part 1
    html.Div(
      className='leftboard',
      style={"border":"1px black solid", 'width':'50%','height':'100%'},
      children=[
      figure=graph_test1()
    ])

   # Part 2
    html.Div(
      className='rightboard',
      style={"border":"1px black solid", 'width':'50%','height':'100%'},
      children=[
      figure=graph_test2()
    ])
])

@app.callback(
Output('leftboard', 'children'),
Input('interval-component', 'n_intervals')
)

def update_graph(n_intervals):
print('UPDATE: ' + str(datetime.datetime.now()))
return graph_test1(), graph_test2()

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

```

**Here is the graph\_test1() function:**

```
from Indicateurs.Models.Frontend.GraphiqueCluster1 import *
from plotly.subplots import make_subplots
import plotly.graph_objects as go

def graph_test1()():

fig = make_subplots(
    rows=1,
    cols=2,
    shared_yaxes=False,
    horizontal_spacing = 0,
)

# First subplot

fig.add_trace(
    go.Bar(
        x=x_month,
        y=product_subplot1,
    ),
1, 1)

fig.update_layout(
    barmode='stack',
    margin=dict(l=0, r=0, t=25, b=15),
    xaxis_title=None,
    yaxis_title=None,
    showlegend=False,
    uniformtext_minsize=20,
    uniformtext_mode='show',
    bargap=0.1,
    yaxis2=go.YAxis(overlaying='y', side='right'),
),

fig.update_traces(
    textfont_size=20,
    textposition='auto',
    #width=1,
),

return fig

```

**Here are the data** (I didn’t put details such as the name of the x abscissa) :

```
# SQL query that we store in a variable
product_S1 = product_query("Product1")

product_subplot1 = [
    product_S1[0]['COUNT(*)']
]

```

Thank you very much !

---

<div class="post-metadata">

**Author:** ![BeginnerDash](https://avatars.discourse-cdn.com/v4/letter/b/53a042/32.png) [@BeginnerDash](https://community.plotly.com/u/BeginnerDash)\
**Post date:** [August 24, 2022, 2:16pm UTC](https://community.plotly.com/t/update-graphs-drawn-from-an-sql-query/67291/2 "2022-08-24T14:16:41Z")

</div>

I made these simple callback and they seem to redo the SQL query each time:

```
@app.callback(
Output('leftboard', 'figure'),
Output('rightboard', 'figure'),
)
def update_graph_frontend_backend(n_intervals):
  return graph_test1(), graph_test2()

```
