I have my table1 on my dashboard so I wanted to create a button below to call out table2. However, it seems like there are some errors in my callback which I could not figure out. Was wondering if the error happens to be at pie = ctx.triggered[0]['prop_id'].split('.')[0]
. Any help would be greatly appreciated!
This is my code
import dash
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import dash_table
from dash.dependencies import Input, Output
from engine import session
from model import datatable1,datatable2,datatable3
import plotly.express as px
table1 = pd.read_sql(session.query(datatable3).statement,session.bind)
table2 = pd.read_sql(session.query(datatable1.Name,datatable1.Number,datatable2.Address).join(datatable2).statement,session.bind)
app = dash.Dash(name, external_stylesheets=[dbc.themes.BOOTSTRAP], suppress_callback_exceptions=True)
app.layout = html.Div([
html.Div(children=[html.Div([
html.H1("Heading", style={'text-align': 'center', 'fontSize': 30}),
dash_table.DataTable(
columns=[{"name": i, "id": i,
'deletable': False,
'renamable': True
} for i in table1.columns],
data=table1.to_dict('records'),
page_current=0,
page_size=20,
page_action='native',
sort_action='native',
column_selectable="single",
sort_mode='multi',
style_table={'overflowX': '',
'maxHeight': '1000px'},
style_header={'backgroundColor': 'rgb(119, 184, 199)'},
style_cell={'backgroundColor': 'rgb(207,227,232)',
'color': 'black',
'whiteSpace': 'normal',
'height': 'auto',
'textAlign': 'left',
},
export_format='xlsx',
export_headers='display',
merge_duplicate_headers=True,
filter_action='native',
editable=True,
row_deletable=True,
sort_by=[]),
dbc.Row(
[
dbc.Col(children=[html.Div([(html.Button('Press',id='test1button')),
dash_table.DataTable(id='table')])])])
])])
])
@app.callback(Output('table', 'data'),
Input('test1button', 'n_clicks'))
def clicked_output(test1button):
ctx = dash.callback_context
if (test1button == None):
return ''
else:
pie = ctx.triggered[0]['prop_id'].split('.')[0]
if pie == 'test1button':
return [
dash_table.DataTable(
columns=[{"name": i, "id": i,
'deletable': False,
'renamable': True
} for i in table2.columns],
data=table2.to_dict('records')
)
]
if name == "main":
app.run_server(debug=True)
My error message is
Invalid argument data passed into DataTable with ID “table”. Expected an array. Was supplied type string. Value provided: “”