Hello,
I’m trying to create an application (using n_interval property) to monitor a log file which is constantly gets updated and get the dataframe through uploaded_jobs() function, and as the log file gets updated, my application would update the data in the table and the graph.
Currently, my graph gets updated but my table doesn’t get updated unless I manually run the code.
Below is my code, I’d appreciate your help (I’ve read almost all the posts related to ‘live update’ but couldn’t figure out my problem).
import dash
from dash import Dash, html, dash_table, dcc, callback, Input, Output
import pandas as pd
import plotly.express as px
from datetime import timedelta, datetime
from uploaded_jobs_past6hrs import *
import plotly.graph_objects as go
import os
from dash.exceptions import PreventUpdate
df = uploaded_jobs()
app = dash.Dash(__name__)
app.layout = html.Div([
html.Div(children='Total number of ' + str(len(df)) +
' job(s) have been uploaded over the past 6 hours', id='update-text'),
html.Div([
dash_table.DataTable(df.to_dict('records'), [
{"name": i, "id": i} for i in df.columns], id='data-table'),
dcc.Graph(id='uploaded-jobs-graph', figure=px.histogram(df, x='Upload_Time', y='Job_ID',
hover_data=['Job_ID', 'Upload_Time'], color='Job_ID', barmode="group", histfunc='count')),
dcc.Interval(id='interval-component', interval=60*1000, # in milliseconds
n_intervals=0)
])], id='container')
@app.callback([Output('uploaded-jobs-graph', 'figure'),
Output('data-table', 'children')],
[Input('interval-component', 'n_intervals')])
def multi_output(n_intervals):
df_updt = uploaded_jobs()
figure = px.histogram(df_updt, x='Upload_Time', y='Job_ID', hover_data=[
'Job_ID', 'Upload_Time'], color='Job_ID', barmode="group", histfunc='count')
table = dash_table.DataTable(df_updt.to_dict('records'), [
{"name": i, "id": i} for i in df_updt.columns], id='data-table')
return figure, table
if __name__ == '__main__':
app.run_server()