Black Lives Matter. Please consider donating to Black Girls Code today.

Plotly Dash table shows up in Jupyter Notebook but not in dash app

I have the following create table function, and it works accordingly in Jupyter Notebook, however when I call it out in the Dash app nothing renders.

def create_table(dataframe):
    fig = go.Figure(data=[go.Table(
    # header=dict(values=['A Scores', 'B Scores'],
    #             line_color='darkslategray',
    #             fill_color='lightskyblue',
    #             align='left'),
    cells=dict(values=[dataframe.columns.values.tolist(), # 1st column
                       df_cohort_3.iloc[0:1].values.tolist()[0]  # 2nd column
    #fig.update_layout(width=500, height=600)

Here is my Dash logic:

app = dash.Dash()

app.layout = html.Div(style={'backgroundColor': colors['background']},

    html.Div(html.H1(children="My Dashboard "))

    #Generate Dash table




if __name__ == '__main__':
    app.run_server(debug=False, port=3005)

Any suggestions?

Hi @Unixmad, you need to change two things in the example

  • the create_table function should return the fig object, not which calls the default renderer to display the figure
  • the plotly figure fig should be the figure argument of a dcc.Graph object, as in

So I changed the function to “return fig”

I then went to the app portion and changed it to :

            'data': [ create_table(df_1)
            'layout': {
                'clickmode': 'event+select'

Not sure I’m inputting the data correctly… sorry also new to python :slight_smile:

it should be figure=create_table(df_1) (we should document this more :-))

1 Like