Hello all, first post so I hope I have the etiquette right?
Any help is appreciated.
I think I am trying to do something similar to the above but have had limited success.
I have 3 charts and a table on my page, and I have the charts updating via intervals (success!).
I’d like to get the table on an interval as well, preferably a different one, but have failed.
So I thought I’d put the whole page on 1 common interval and failed in that.
Here is my code (mostly gutted):
# -*- coding: utf-8 -*-
# external deps
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, State
import dash_table
import plotly.graph_objects as go
from dash_table.Format import Format, Group, Scheme, Symbol
# internal dependencies
import dataparser #prepares data
import chart1
# global vars
Fcolor = 'rgba(0,0,0,0)'
Fsize = 10
Host = '0.0.0.0'
port = 9999
updatePeriod = 30*1000, # in milliseconds
data = {}
dfTable = []
external_css = ["styling.css"]
app = dash.Dash(__name__, external_stylesheets=external_css)
timestamp = "Updated: "+dt.datetime.now().strftime("%H:%M %d/%m/%y")+"(GMT)"
def colors(col):
#create palette
return colorlist
def get_banner():
#create banner
return banner
def create_charts(df1, figure2):
global dfTable
# do some math, create dfTable
global data
data = df1
banner = get_banner()
app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
html.Div(id="page-content"),
dcc.Interval(id="interval", n_intervals=0, interval=updatePeriod),
#Create Header Region
html.Div([
html.Div([banner], style={'color': 'red'},),
html.Marquee([banner], style={'color': 'orange'})
], className="row"),
html.Header([html.Img(src='./Header.jpg')], style={'height': '33%', 'width': '10%'},),
html.Div(timestamp, style={'color': Fcolor, 'font-size':Fsize, 'margin-left':'88%'}),
html.Br(),
dcc.SayHello(id='say-hello',
children=html.Div(['Hola!',html.Br(),]),
style={'width': '10%', 'height': '60px'},
),
html.Div(id='output-data-upload'),
######################################################Graphs & Charts
dash_table.DataTable(id='datatable',
columns = tablecols,
style_as_list_view=True,
data=dfTable.to_dict('records'),
sort_action="native", page_action='none',
row_selectable="", row_deletable=False, selected_row_ids=[0],
active_cell={'row_id': dfTable['id'][0], 'row': 0, 'column': 0, 'column_id': 'NAME'},
style_table={'height': '270px', 'width':'83%'},
fixed_rows={'headers': True}
),
html.Div(id='datatable-container'),
#############################banner
html.Div("Thank You!", style={'font-style': 'italic'}),
html.Div(id='XYZ'),
html.Br(),
html.Div([
html.Div([dcc.Graph(id='graph1'),
dcc.Interval(id='intervalG1', interval=updateTime, n_intervals=0
),
], className="half"),
html.Div([dcc.Graph(id='graph2'),
dcc.Interval(id='intervalG2', interval=updateTime, n_intervals=0
),
], className="half"),
], className="row"),
html.Br(),
################################### bubble2/animation
html.Div([
html.Div([dcc.Graph(figure=figure2)], className="full"),
], className="row"),
####################################Footer
html.Footer("2021", style={'textAlign':"center"})
], className="row")
#________________________________________________________________________________
@app.callback(
[Output('page-content', 'children')],
[Input('interval', 'n_intervals')],
)
@app.callback(
Output('XYZ', 'children'),
[Input('upload-data', 'contents')],
[State('upload-data', 'files')]
)
def parse_contents(contents, files, date):
if contents is not None:
#check files
return html.Div(['All done.'])
if filename is None: return
@app.callback(
[Output('graph1', 'figure'), Output('graph2', 'figure')],
[Input('datatable', 'selected_row_ids'),Input('datatable', 'active_cell'), Input('intervalG1', 'n_intervals'), Input('intervalG2', 'n_intervals')]
)
def update_figures(selected_row_ids, active_cell, n, m):
#create figures
return figtrace1, figtrace2
if __name__ == '__main__':
df1 = dataparser.getinfo()
figure2 = chart1.render()
create_charts(df1, figure2)
app.run_server(debug=False, use_reloader=True, port=port, host=Host)