I have a dash app where a table should be displayed depending on the user input in a textbox. But when I run my code, the table is not displayed. Here is the relevant part of my code:
import dash
from dash.dependencies import Output, Event, Input
import dash_core_components as dcc
import dash_html_components as html
import plotly
import plotly.graph_objs as go
import pandas as pd
import sqlite3
import requests
app = dash.Dash()
app.layout = html.Div(children=[
html.Div([
dcc.Input(id='input', placeholder='Enter the input...', type='text')
]),
html.Div([
html.Div(id='my-table'),
dcc.Interval(
id='table-update',
interval=2*1000
),
])
])
@app.callback(Output('my-table', 'children'),
[Input(component_id='input', component_property='value')],
events=[Event('table-update', 'interval')])
def update_recent_tweets(input_data):
conn = sqlite3.connect('database.db')
c = conn.cursor()
df = pd.read_sql("SELECT * FROM Col1 WHERE Col2 LIKE ? ORDER BY Col3 DESC LIMIT 10", conn, params=('%' + input_data + '%',))
trace = go.Table(
header=dict(values=list(df.columns),
fill = dict(color='#C2D4FF'),
align = ['left'] * 5),
cells=dict(values=[df.Col1, df.Col2, df.Col3],
fill = dict(color='#F5F8FF'),
align = ['left'] * 5))
return {'data':[trace]}
if __name__ == '__main__':
app.run_server(debug=True)
The error it gives says the input cannot be found in the database. But its there in it, I know because my app has some more plots, and the other plots dependent on the same input work fine. What’s wrong with the table code?