Dash table in not created in the second page of the dash application

I am trying to building a webapp in plotly-dash. It’s a two page web application. In page one, I have four dropdowns. What I am trying to do is, upon selecting the values from the dropdowns and hitting the submit button. The values chosen in the dropdown will serve as filters for the table to be generated in the second page.

I am storing all the dropdown values in dcc.Store .

@app.callback(Output("filters",'data'),
              Input('mki_dropdown','value'),
              Input('brd_dropdown','value'),
              Input('pyt_dropdown','value'),
              Input('pya_dropdown','value')
             )
def filter_input(selected_mki,
                 selected_brd,
                 selected_pyt,
                 selected_pya
                ):
    user_input = {
        "mki":selected_mki,
        "brd":selected_brd,
        "pyt":selected_pyt,
        "pya":selected_pya
    }    
    return user_input    

This is the second page where the dash table is generated.

layout_page_2 = html.Div([
    html.Div([
        html.H4("P.E.L"),
        html.Div(className="row",children=[
            html.Div([
                html.Label(['ACS'], style={'font-weight':'bold'}),
            ],style=dict(width="10%")),
            html.Div([
               dcc.Dropdown(
                id = "acs_dropdown",
                options=[{'label':s,'value':s} for s in list(sta)],
                placeholder = "Select ACS",
                searchable = False,
            )],style = dict(width="30%",padding="6px")), 
        ],style=dict(display="flex")),
        html.Br(),
        dash_table.DataTable(
            id = "table",
            editable = True,
            filter_action = "native",
            sort_action="native",
            sort_mode="multi",
            selected_columns=[],
            selected_rows=[],
            column_selectable="single",
            row_selectable="multi",
            style_cell = {'fontSize':'15px'}, 
            fixed_rows = {'headers':'True'},  
            page_size=20,
            style_table = {'height':'300px','overflow':'auto'}
        ),
    ]),    
])

Using this callback, I am trying to send in the dropdown values via dcc.Store to the columns and data parameter of the dash table.

@app.callback(Output("table","columns"),
              Ouput("table","data"),
              Input("filters","data"))
def table_data(user_inputs):

    mki = user_inputs["mki"]
    brd = user_inputs["brd"]
    pyt = user_inputs["pyt"]
    pya = user_inputs["pya"]

    table_df = df2.copy()
    table_df.query('MKI == @mki and BRD == @brd and PYT == @pyt and PYA == @pya',inplace=True)
    flt_df=table_df[['PEI','PEN','TL','CA']]

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

    return col,data

I am trying to building a webapp in plotly-dash. It’s a two page web application. In page one, I have four dropdowns. What I am trying to do is, upon selecting the values from the dropdowns and hitting the submit button. The values chosen in the dropdown will serve as filters for the table to be generated in the second page.

I am storing all the dropdown values in dcc.Store .

@app.callback(Output("filters",'data'),
              Input('mki_dropdown','value'),
              Input('brd_dropdown','value'),
              Input('pyt_dropdown','value'),
              Input('pya_dropdown','value')
             )
def filter_input(selected_mki,
                 selected_brd,
                 selected_pyt,
                 selected_pya
                ):
    user_input = {
        "mki":selected_mki,
        "brd":selected_brd,
        "pyt":selected_pyt,
        "pya":selected_pya
    }    
    return user_input    

This is the second page where the dash table is generated.

layout_page_2 = html.Div([
    html.Div([
        html.H4("P.E.L"),
        html.Div(className="row",children=[
            html.Div([
                html.Label(['ACS'], style={'font-weight':'bold'}),
            ],style=dict(width="10%")),
            html.Div([
               dcc.Dropdown(
                id = "acs_dropdown",
                options=[{'label':s,'value':s} for s in list(sta)],
                placeholder = "Select ACS",
                searchable = False,
            )],style = dict(width="30%",padding="6px")), 
        ],style=dict(display="flex")),
        html.Br(),
        dash_table.DataTable(
            id = "table",
            editable = True,
            filter_action = "native",
            sort_action="native",
            sort_mode="multi",
            selected_columns=[],
            selected_rows=[],
            column_selectable="single",
            row_selectable="multi",
            style_cell = {'fontSize':'15px'}, 
            fixed_rows = {'headers':'True'},  
            page_size=20,
            style_table = {'height':'300px','overflow':'auto'}
        ),
    ]),    
])

Using the callback, I am trying to send in the dropdown values via dcc.Store to the columns and data parameter of the dash table.

@app.callback(Output("table","columns"),
              Ouput("table","data"),
              Input("filters","data"))
def table_data(user_inputs):

    mki = user_inputs["mki"]
    brd = user_inputs["brd"]
    pyt = user_inputs["pyt"]
    pya = user_inputs["pya"]

    table_df = df2.copy()
    table_df.query('MKI == @mki and BRD == @brd and PYT == @pyt and PYA == @pya',inplace=True)
    flt_df=table_df[['PEI','PEN','TL','CA']]

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

    return col,data

But what ends up happening is that after choosing the dropdown values and clicking the submit button in the first page. The application proceeds to the second page but the table is not generate. In place of the table, there is just blank space.

I can’t figure out what I am missing here.

Thanks in advance.

Hi,

Welcome to the community! :slight_smile:

Do you see any errors in the application when running it with debug=True? Besides that, where is the dcc.Store defined in the layout? Is it in page 1 or in the same level as the “content-page” container?

Hi

No errors pop-up when I run the application.
dcc.Store is defined in the layout_page_1. The page with dropdown menus and submit button.

This is the dash code for page 1 and it’s callbacks.

layout_page_1 = html.Div([
    html.Label(['Select Below Fields'], style={'font-weight':'bold','text-align':"center","color":"#04aa6d","padding":"8px","font-size":"22px"}),
    html.Br(),
    html.Div(className='row', children = [
        html.Div([
            html.Label(['MKI'], style={'font-weight':'bold',"color":"#2196f3","display": "block","padding-left":"5px","font-size":"22px"}),
        ],style = dict(width="30%")),
        html.Div([
            html.Label(['BRD'], style={'font-weight':'bold','text-align':"center","color":"#2196f3","font-size":"22px"}),
        ],style = dict(width="30%")),
        html.Div([
            html.Label(['PYT'], style={'font-weight':'bold','text-align':"center","color":"#2196f3","font-size":"22px"}),
        ],style = dict(width="30%")),
        html.Div([
            html.Label(['PYA'], style={'font-weight':'bold','text-align':"center","color":"#2196f3","font-size":"22px"}),
        ],style = dict(width="30%")),
        html.Div([
            html.Label(['PR'], style={'font-weight':'bold','text-align':"center","color":"#2196f3","font-size":"22px"}),
        ],style = dict(width="30%")),        
    ],style=dict(display='flex',justifyContent='center')),

	html.Label(['Filter/Dropdown'], style={'font-weight':'bold','text-align':"center","color":"#04aa6d","padding":"8px","font-size":"15px"}),
    html.Br(),

    html.Div(className="row",children =[
        html.Div(className='six columns', children=[
            dcc.Dropdown(
                id = "mki_dropdown",
                options=[{'label':m,'value':m} for m in list(mki_d)],
                placeholder = "Select MKI",
                searchable = False,
            )],style = dict(width="30%",padding="6px")),
        html.Div(className='six columns', children=[
            dcc.Dropdown(
                id = "brd_dropdown",
                placeholder = "Select BRD",
                searchable = False,
            )],style = dict(width="30%",padding="6px")),
        html.Div(className='six columns', children=[
            dcc.Dropdown(
                id = "pyt_dropdown",
                placeholder = "Select PYT",
                searchable = False,
            )],style = dict(width="30%",padding="6px")),
        html.Div(className='six columns', children=[
            dcc.Dropdown(
                id = "pya_dropdown",
                placeholder = "Select PYA",
                searchable = False,
            )],style = dict(width="30%",padding="6px")),
        html.Div(className='six columns', children=[
            dcc.Dropdown(
                id = "pr_dropdown",
                options=[{'label':t,'value':t} for t in list(prd_d)],
                placeholder = "Select PR",
                searchable = False,
            )],style = dict(width="30%",padding="6px"))], style=dict(display='flex')),
# dcc.Store            
    dcc.Store(id="filters",storage_type="memory"),
    html.Br(),
    dcc.Link(
        html.Button('Submit',id='submit_button'),
        href='page-2'),
])

@app.callback(Output('brd_dropdown','options'),
              Input('mki_dropdown','value')
             )
def update_market(selected_mki):
    print(selected_mki)
    m_df = df2.copy()
    m_df.query('MKI == @selected_mki',inplace=True)
    brd_dropdown = m_df["BRD"].unique()
    return [{'label':b,'value':b} for b in list(brd_dropdown)]


@app.callback(Output('pyt_dropdown','options'),
              Input('mki_dropdown','value'),
              Input('brd_dropdown','value')
             )
def update_payment(selected_mki, selected_brd):
    p_df = df2.copy()
    p_df.query('MKI == @selected_mki and BRD == @selected_brd',inplace=True)
    pyt_dropdown = p_df["PYT"].unique()
    return [{'label':p,'value':p} for p in list(pyt_dropdown)]


@app.callback(Output('pya_dropdown','options'),
              Input('mki_dropdown','value'),
              Input('brd_dropdown','value'),
              Input('pyt_dropdown','value')
             )
def update_account(selected_mki, selected_brd, selected_pyt):
    a_df = df2.copy()
    a_df.query('MKI == @selected_mki and BRD == @selected_brd and PYT == @selected_pyt',inplace=True)
    pya_dropdown = a_df["PYA"].unique()
    return [{'label':a,'value':a} for a in list(pya_dropdown)]

Ok. Try to move the dcc.Store to the main layout. If it is in page 1, then it will be removed from the layout when page 2 loads and the callback will not be triggered.