Hi, total newbie. I am struggling with how to have my dashboard automatically update. I have a very simple dashboard, at this time, jsut a H3 displaying the system date/time.
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output
import plotly.graph_objs as go
#Setup for Dash
external_stylesheets = [dbc.themes.SIMPLEX]
app = dash.Dash(name, external_stylesheets=external_stylesheets)
app.title=âWeather Stationâ
colors = {
âbackgroundâ: â#000000â,
âbodyColorâ: â#00000â,
âtextâ: â#FFFFFFâ,
âredâ: â#FF0800â
}
dt_time = datetime.now()
print (dt_time)
app.layout = html.Div([
#html.H3(children=[display_dow, " - - ", display_date, " - - ", display_time],
html.H3(children=["Hello ", dt_time],
id="head1",
style={
'textAlign': 'center',
'backgroundColor': colors['red'],
'color': colors['text']
}),
dcc.Interval(
id='interval-component',
interval=1*1000,
n_intervals=0)
])
@app.callback(Output(âhead1â,âchildrenâ),
Input(âinterval-componentâ,ân-intervalsâ))
print(âHello worldâ)
if name == âmainâ:
app.run_server(debug=False)
I added the Print(âHello worldâ) simply to ensure I had no error in the that is erroring out.
Whenever I run the program, I get an error on the line immediately after the @app.callback
%Run simple_dashboard.py
Traceback (most recent call last):
File â/home/pi/Desktop/simple_dashboard.pyâ, line 46
print(âHello worldâ)
^
SyntaxError: invalid syntax
I believe I am using the correct format for the @app.callback, but as I mentioned, no matter what I have after this, results in an error.
If I comment out the 2 lines for the app.callback, the dasboard renders properly.
Any thoughts would be appreciated.
If it helps understand my purpose, I am trying to develop a dashboad for my weather station. All my readings are published to a MQTT server (Pubnub) and I want a dashboard which subscribes to the channel and displays the results. I am able to subscribe to Pubnub, create a dashboard and manually refresh the browser (running on a Raspberry PI4), all thatâs left is to automatically refresh the data once a minute (either on timer or on subscribe results),
Thanks