Dear community,
I am new to Plotly and dash and want to build my first app.
Is there a general option to update/refresh the whole app in a pre-defined time (such as every 5 seconds).
I know about this website (dash.plot.ly/live-update) and others, but I cannot apply on my use case.
I would highly appreciate if you may help me.
Besides reading JSON documents, I will also show PNG files. As another tool is updating these PNG and JSON files permanently, the app should refresh itself.
The current draft is as follows:
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
from flask import Flask, Response
import base64
external_stylesheets = [‘https://codepen.io/chriddyp/pen/bWLwgP.css’]
server = Flask(name)
app = dash.Dash(name, external_stylesheets=external_stylesheets, server=server)
df =pd.read_json(“convertcsv.json”)
def generate_table(dataframe, max_rows=10): return html.Table(
Header
[html.Tr([html.Th(col) for col in dataframe.columns])] +
Body
[html.Tr([
html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
]) for i in range(min(len(dataframe), max_rows))]
)
###Image
image_filename = ‘graph.png’ # replace with your own image
encoded_image = base64.b64encode(open(image_filename, ‘rb’).read()).decode(‘ascii’)
###App-Layout
app.layout = html.Div([
html.Div([
generate_table(df)]),
html.Div([
html.Img(src=‘data:image/png;base64,{}’.format(encoded_image))
]),
])
app.css.append_css({
‘external_url’: ‘https://codepen.io/chriddyp/pen/bWLwgP.css’
})
if name == ‘main’:
app.run_server(debug=True)
Thank you very much in advance!