ID not found in layout in data table

What it the issue in this code?

Plz help me

import pandas as pd
import numpy as np
from dash import Dash, dash_table, dcc, html
from dash.dependencies import Input, Output
from datetime import date, datetime

df = pd.read_excel(‘Data.xlsx’)
filt_df_table = pd.pivot_table(data=df, index=[“CreatedMonth”],
columns=[“CustType”],
values= [“TotalPax”],
aggfunc=“count”,
fill_value=0,
margins= True,
margins_name=“Total”)

filt_df_table.columns = filt_df_table.columns.droplevel(0)
filt_df_table.columns.name = None
filt_df_table = filt_df_table.reset_index()

print(filt_df_table)

app = Dash(name)

app.layout = html.Div([
html.H1(‘Type wise INQ Report’, style = {‘alignment’:‘center’,‘color’:‘blue’,‘border’:‘5px green solid’, ‘width’:‘25%’}),
dcc.DatePickerRange(
id=‘date_picker’,
start_date=df[‘CreatedOn’].min(0),
end_date=df[‘CreatedOn’].max(),
show_outside_days=True,
day_size=32,
display_format=‘DD/MM/YYYY’,
clearable=True,
)])

@app.callback(Output(‘datatable’,‘children’),
[Input(‘date_picker’,‘start_date’),
Input(‘date_picker’,‘end_date’)])

def update_table(start_date,end_date):

filt_df_table = df.loc[(df['CreatedOn'] >= start_date)
                 & (df['CreatedOn'] < end_date)]
filt_df_table = pd.pivot_table(data=filt_df_table, index=["CreatedMonth"], 
                        columns=["CustType"], 
                        values= ["TotalPax"],
                        aggfunc="count",
                        fill_value=0,
                        margins= True, 
                        margins_name="Total")

filt_df_table.columns = filt_df_table.columns.droplevel(0)
filt_df_table.columns.name = None
filt_df_table = filt_df_table.reset_index()

df = filt_df_table.to_dict('records')
columns =  [{"name": i, "id": i,} for i in (filt_df_table.columns)]


datatable = dash_table.DataTable(
    id='datatable-interactivity',
    columns=[{"name": i, "id": i, "deletable": True, "selectable": True} for i in filt_df_table.columns],
    data=filt_df_table.to_dict('records'),
    editable=True,
    filter_action="native",
    sort_action="native",
    sort_mode="multi",
    column_selectable="single",
    row_selectable="multi",
    row_deletable=True,
    selected_columns=[],
    selected_rows=[],
    page_action="native",
    page_current= 0,
    page_size= 15,
    ),
html.Div(id='datatable-interactivity-container')
        

return datatable

if name == ‘main’:
app.run_server(debug=True)

Screenshot_1

Hi Vicky. Welcome.

Besides the obvious error, it would be beneficial for anyone looking at this to describe what you would try to achieve.

The error states or means that the output id you are targeting does not exist (there is no item in your code with the id datatable)

In addition you are target the children attribute which would mean you need some form of div with I’d of datatable.

But all in all I would think that this would not the real issue here. Please try to describe what you are actually trying to achieve

Reg,
J.

1 Like

Hi,

Thanks for your quick Response,

Actually, i want to achieve, i have data sheet with so many row and column, i need to filter data as per i selected (date range) in dash. (ex. Date, City, Country etc…)

Please help me i’m beginner.

And data table reflect as per selection.

Hi, I haven’t checked all of the code regarding your data, but as far as things look now your are missing an additional div in your layout with the id datatable .

Something like

app.layout = html.Div([
html.H1(‘Type wise INQ Report’, style = {‘alignment’:‘center’,‘color’:‘blue’,‘border’:‘5px green solid’, ‘width’:‘25%’}),
dcc.DatePickerRange(
id=‘date_picker’,
start_date=df[‘CreatedOn’].min(0),
end_date=df[‘CreatedOn’].max(),
show_outside_days=True,
day_size=32,
display_format=‘DD/MM/YYYY’,
clearable=True,
),
html.Div(id='datatable')
])

Thanks for your response…

I tried this but not working.

Screenshot_1

Thanks for your support