Hello, I’m fairly new to python and very new to Dash but I’ve go a couple of bar and line charts working where they query a database at set intervals and display the data. I’m trying to do the same with a data table but I’m unable to, I was wondering if anyone could help me out? Thanks in advance.
EDIT: here’s my code for trying to get just the table working, there are extra imports because I just kept all the ones from the main project.
from __future__ import division import dash from dash.dependencies import Output, Event, Input import dash_core_components as dcc import dash_html_components as html import dash_table_experiments as dt from datetime import datetime as dtt import csv import pymysql import pandas as pd import plotly.plotly as py import plotly.graph_objs as go import random from collections import deque conn = pymysql.connect( host='', user='', password='', db='') app = dash.Dash() app.layout = html.Div([ html.Div([ html.H2('Table'), html.Div(id='Table'), ]), ], ) def generate_table(a, max_rows=100): return html.Table(className="table", children=[ html.Thead( html.Tr( children=[ html.Th(col.title()) for col in df.columns.values] ) ), html.Tbody( [ html.Tr( children=[ html.Td(data) for data in d] ) for d in df.values.tolist()]) ] ) @app.callback(Output('Table', 'children')) def update_recent_data(): a = conn.cursor() a.execute("Query that returns x amount of columns and a variable amount of rows") a = a[['column1','column2',,,'columnx']] return generate_table(a, max_rows=100) if __name__ == '__main__': app.run_server(debug=True)