Return an empty graph

I am trying to get Dash to return nothing when no Data is selected. To do this I have added an if statement in my callback that should return nothing when no Data is selected.

However Dash is not clearing the existing graph.

Graph with two Data sets selected

Graph with one Data set selected

Graph with no Data set selected

In my callback I have tried getting it to return , {}, {}, None and {‘data’: }.

However they either return an error and the graph stays or they don’t return an error and the graph stays.

What should I be asking it to return so that no plot appears.

My callback:

def Make_Histograms_Graph(af,Click,Column,Min,Max,Bins,Title,Combo):
if Click < 1:
    return []
else:
    print(Column == [])
    if Column == []:
        return {'data': []}
    else:
        df = pd.read_json(af, orient='split')
        if not df.empty:
            a = Show_Histograms_Combo(df,Column,Min = Min, Max = Max, Bins = Bins, Title = Title,Combo = Combo)
            return {
                'data': a[0],
                'layout': a[1],
            }
        else:
            return [{}]

Using print commands I have verified that it is going into the if statement where the return “blank” is located.

I was wondering if anyone knows how to fix this.

Many Thanks

Turns out that return {‘data’: []} does work but due to an errors in my code it wasn’t appearing.

2 Likes

Actually return {‘data’: []} returns a blank graph. To return nothing just return []

1 Like

Its a bug in dash… If you could produce a reproducible example for chris, that would be great!

Is there any update on this?

Here’s a snippet I used in my code, that worked for me.

if(len(ds4a_value)<=0):
        fig1 = go.Figure().add_annotation(x=2, y=2,text="No Data to Display",font=dict(family="sans serif",size=25,color="crimson"),showarrow=False,yshift=10)
        fig2 = go.Figure().add_annotation(x=2, y=2,text="No Data to Display",font=dict(family="sans serif",size=25,color="crimson"),showarrow=False,yshift=10)
        return fig1,fig2