import dash, random, datetime
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import dash_table
import pandas as pd
from sqlalchemy.orm import sessionmaker
from models import Title, db_connect, create_table, Domain
columns= [column.key for column in Title.__table__.columns]
external_stylesheets = ['https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css']
engine = db_connect()
create_table(engine)
Session = sessionmaker(bind=engine)
session = Session()
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.scripts.append_script({"external_url": "https://code.jquery.com/jquery-3.3.1.js"})
app.layout = html.Div([
dash_table.DataTable(
id='datatable',
columns=[{"name": i, "id": i} for i in columns],
data=[],),
dcc.Interval(
id='interval-component',
interval=1*5000, # in milliseconds
n_intervals=0
),
],)
@app.callback(Output('datatable', 'data'),
[Input('interval-component', 'n_intervals'),])
def update_metrics(n):
query = session.query(Title).all()
data = []
for q in query:
title = q.__dict__
del title['_sa_instance_state']
data.append(title)
return data