Dbc.modal will not display Plotly table but will display Plotly subplots with dcc.Graph used for both calls

I have created a dash app that uses the dbc.modal command to display detailed data when a button is clicked.
The modal displays all the elements requested accept a data table i created with plotly.
The modal includes two drop downs, an html string, the data table and a subplot. All display except the table. No error is displayed and the placeholder coordinate frame is displayed but the table is not.

Here is the code:

    html.Div(
        [
            dbc.Modal(
                children = [
                dbc.ModalHeader(
                    children = [
                        dbc.ModalTitle('Decorating Machine Details',style={"textAlign": "center"}),                         
                    ]
                ),
                dbc.ModalBody(children = [
                        dcc.Dropdown(['Bander 4', 'Bander 3', 'Cerinnov','Kammann 1','Kammann 2','Kammann 3','Rotary Screen 1','Rotary Screen 2','Isimat'],
                        id={'type': 'decdropdown','index': 'finishing'},
                        value = 'Bander 4',
                        placeholder="Select Decorating Machine",
                        ),
                        dcc.Dropdown(['A1', 'A2', 'C1','C2','D1','D2'], id={'type': 'lehr-dropdown','index': 'finishing'},placeholder = "Select Lehr Lane",value = 'D2'),
                        html.Pre(id={'type': 'lehrproduct','index': 'finishing'},
                            style={
                            'textAlign': 'left','fontSize': 19,'marginBottom': 0, 'marginTop': 1, 'font-family':'Arial Black'
                        }),
                        dcc.Graph(id={'type': 'pickupTable','index': 'finishing'},
                         style={"height":300}),
                        dcc.Graph(id={'type': "modaltrends",'index': 'finishing'})
                        ]),
                ],
                id="decmachine-modal",
                size="xl",
                centered=True,
                is_open=False,
            ),
        ],
        className="mb-3",
    ),

And here is the code for the callback that builds the table and the “lehrproduct” element.

@callback(
Output({‘type’: ‘lehrproduct’,‘index’: MATCH}, ‘children’),
Output({‘type’: ‘pickupTable’,‘index’: MATCH}, ‘children’),
Input({‘type’: ‘fini_process’,‘index’:MATCH},‘children’),
Input({‘type’: ‘lehr-dropdown’,‘index’: MATCH}, ‘value’),
Input({‘type’: ‘lehrPickupType’,‘index’:MATCH},“children”),
Input({‘type’: ‘finimajors’,‘index’:MATCH},“children”),
Input({‘type’: ‘finiminors’,‘index’:MATCH},“children”),
)
def buildfinishingqualitytable(products_json,lehr,QCAction,dffinimajors_json,dffiniminors_json):
dfproducts = pd.read_json(products_json,orient =‘split’)
dffinimajors=pd.read_json(dffinimajors_json,orient =‘split’)
dffiniminors=pd.read_json(dffiniminors_json,orient =‘split’)
print(‘getFinishingproduct’)

title = "{} - {} - {} - {}".format(lehr,str(dfproducts['product'].loc[lehr]),str(dfproducts['process'].loc[lehr]),QCAction)
#titleD2 = "<b>D2 - {} Sel: {} spd:{}</b>".format(str(dfproducts.loc['523'].values[0]),str(poss523),str(speed523))
headerColor = 'grey'
rowEvenColor = 'lightgrey'
rowOddColor = 'white'
print(title)
#header=dict(
#      values=['<b>Lehr</b>','<b>D1</b>','<b>D2</b>','<b>C1</b>','<b>C2</b>','<b>A1</b>','<b>A2</b>'],
#          
#      fill_color=['white'],
##      align=['center'],
#      font=dict(color='black', size=16),
#      line=dict(color='black')
#    ),

print(dffinimajors['result'].loc[0])
print(dffiniminors['result'].loc[0])

figtab = go.Figure(data=[go.Table(
    header=dict(
          values=['Class'],
          fill_color=['white'],
          align=['center'],
          font=dict(color='black', size=16),
          line=dict(color='black')
        ),
    cells=dict(
        values=[
            ['Majors','Minors'],
        ],
        line_color='darkslategray',
        align = ['center'],
        font = dict(color = 'black', size = 12),
    )
  ),
])
figtab.update_layout(
    margin=dict(
      l=10,
      r=10,
      b=1,
      t=20,
      pad=2
      ),
    showlegend=False
)
print(figtab)
return title, \
       figtab

I know the callback is executing correctly because “lehrproduct” is correctly returned when the modal is entered. I am using dash 2.6.2

This is how the modal is displayed:

Hello @hoylerbr,

In your code, what is the output of your print statement?

Just trying to understand your code, but what is the purpose of the pattern-matching in this instance? I think this might be causing the issue. To test, comment out the title output and see if the graph returns as expected.

Hello jinnyzor,
The print statements are used for debugging and display on the Visual Code console view. I use them to verify the code worked that far at least.
I just tried commenting out the title output and the modal worked the same - only without the title appearing.
When I first wrote the code I did not use the pattern-matching and it would not work at all. I use pattern matching throughout the dashboard application.
I found an obscure referance to a bug in an early version of dash that may apply here but the thread says the bug has been fixed. [BUG] Dash 1.6 Datatable disables all callbacks if not in initial layout · Issue #1010 · plotly/dash · GitHub

I have been using the similar go.table statements with dcc.Graph throughout my application and the only place it dosent work is in the modal.

Does the print(figtab) print an actual table?

I dont think you should have an issue with the table being returned, otherwise people wouldnt be able to upload csv, translate to datatable and use for data further down the line.

I had hoped it would. It returned the structure for figtab. Below is a screen shot of what it returns.

image

The output needs to return to the figure, not the children.

1 Like

I have used similar code to display tables in several places in my dashboard without a problem. This is the only place I have tried to display a table in a dbc.modal. This has me wondering if there is some incompatibility between go.Figure(data=[go.Table and dbc.ModalBody.

Face palm - head smack.

That was it! I have been staring at the code for 3 days and did not notice that!
Thank you Very MUCH.

1 Like

Sometimes, it is the simple things that make it the most tricky. That’s the problem with complex apps. Haha.

2 Likes