I have a dashboad with two parts, part 1 and part 2.
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 !