Dash This page is not responding

Hi,
I have a dash app that implement a predefined class inside it. the dash is designed to produce plots depending on specific paymasters: type-picker: F, M or R, which in return determines the data-picker and plot-picker.
once these values are chosen, the class test_stat is called and the method stat_test is applied to the chosen data (.csv) performing specific statistical tests, such as chi square and AD test, which are then passed on to the last callback to produce graphs.
Without dash, the Program works perfectly. With dahs however, i used to have many errors which i tried to correct. the latest update is i have no error codes, however, the app is just frozen, can’t interact with the bottoms and stays there without displaying anything and i only get the message ’ This page is not responding’.
I can’t figure out what is the problem. Is it because i am using a predefined class inside the app? (the class takes some time to do the calculations, but not much), or i am doing something wrong with the callbacks?
Any help is appreciated
Thanks
below is the code:

data_type = [‘F’, ‘M’, ‘R’]
data_dict = data_namer(names_list[:-2])[0]

def data_picker(data_type):
return data_dict[data_type]

app = Dash()
app.layout = html.Div(id = ‘main-div’,
children=[
html.H4(‘Raw data Statistical tests’),
html.P(‘Chose data type:’),
dcc.RadioItems(data_type, value = data_type[0], id = ‘type-picker’),
html.P(‘Chose plot:’),
dcc.RadioItems( id=‘plot-picker’), #value = ‘chi’,
html.P(‘Chose data:’),
dcc.Dropdown(id = ‘data-picker’, multi = True),
dcc.Graph(id = ‘plot’) ]

                    )

@app.callback(Output(‘plot-picker’,‘options’), [Input(‘type-picker’, ‘value’)])
def plot_picker(type_pick):
if type_pick == ‘R’:
return [‘chi’, ‘ks’, ‘ks_D_below’, ‘ad’, ‘chi_row’, ‘ad_row’]
if type_pick == ‘M’:
return [‘chi’, ‘ks’, ‘ks_1’, ‘ad’]
if type_pick == ‘F’:
return [‘chi’, ‘ks’, ‘ks_1’, ‘ad’]

@app.callback(Output(‘data-picker’,‘options’), [Input(‘type-picker’, ‘value’)])
def data_picker(type_pick):
return data_dict[type_pick]

@app.callback(Output(‘plot’,‘figure’),
[Input(‘type-picker’, ‘value’), Input(‘data-picker’, ‘options’), Input(‘plot-picker’, ‘options’)])
def plot_data(type_pick, data_pick, plot_pick):

if type_pick == 'R':
    #['chi', 'ks', 'ks_D_below', 'ad', 'chi_row', 'ad_row']
    #chi test
    if plot_pick == 'chi':
        data = []
        for data_ in data_pick:
            path = data_ + '//' + type_pick.lower()+ '_test'
            name = data_
            test_1=test_stat(path, type_pick.lower())
            test_1.stat_test()
            chi_1 = test_1.chi_1
            trace = [go.Scatter(x = np.arange(1, len(chi_1)+1)/len(chi_1), y = sorted([x[0] for x in chi_1]), mode ='lines+markers', name='chi_'+name)]
            data.append(trace)
        layout = go.Layout(title='chi_square for {}, #tests: {} ({}_test)'.format(name, len(test_1.header), type_pick))
        fig_chi = go.Figure(data, layout)
        fig_chi.add_hline(y=np.mean([x[0] for x in chi_1]), line_width=1, line_dash="dash", line_color="red", annotation_text='mean_'+name, annotation_position="bottom right")
        fig_chi.add_hline(y=np.median([x[0] for x in chi_1]), line_width=1, line_dash="dash", line_color="orange", annotation_text='median_'+name, annotation_position="bottom left")
        fig_chi.update_xaxes(title_text = 'Individual Tests')
        fig_chi.update_yaxes(title_text = 'p_value')
        return fig_chi
            
    elif plot_pick == 'chi_row':
        data_row = []   
        for data_ in data_pick: 
            path = data_ + '//' + type_pick.lower()+ '_test'
            name = data_
            test_1=test_stat(path, type_pick.lower())
            test_1.stat_test()
            chi_1_row = test_1.chi_1_row
            trace= [go.Scatter(x = np.arange(1, len(chi_1_row)+1)/len(chi_1_row), y = sorted([x[0] for x in chi_1_row]), mode ='lines+markers', name='chi_'+name)]
            data_row.append(trace)
        layout_row = go.Layout(title='chi_square for{}, #tests: {} ({}_test)'.format(name, len(test_1.header), type_pick))
        fig_chi_row = go.Figure(data_row, layout_row)
        fig_chi_row.add_hline(y=np.mean([x[0] for x in chi_1_row]), line_width=1, line_dash="dash", line_color="red", annotation_text='mean_'+name, annotation_position="bottom right")
        fig_chi_row.add_hline(y=np.median([x[0] for x in chi_1_row]), line_width=1, line_dash="dash", line_color="orange", annotation_text='median_'+name, annotation_position="bottom left")
        fig_chi_row.update_xaxes(title_text = 'Individual Tests')
        fig_chi_row.update_yaxes(title_text = 'p_value')
        return fig_chi_row

    #ks test
    elif plot_pick == 'ks_D_below':
        data = []
        for data_ in data_pick:
            path = data_ + '//' + type_pick.lower()+ '_test'
            name = data_
            test_1=test_stat(path, type_pick.lower())
            test_1.stat_test()
            ks_1_below = [(x[0][0], x[1]) for x in test_1.ks if x[0][0] <= x[0][1]]
            ks_1_list = []
            for h in test_1.header:
                ks_ = []
                for x in ks_1_below:
                    if x[1] == h:
                        ks_.append(x[0])
                ks_1_list.append(ks_)
            header_1 =test_1.header
            y_1 = [len(x) for x in ks_1_list]
            trace= [go.Bar(x = header_1, y =y_1,text = y_1,)]
            data.append(trace)
        layout_1 = go.Layout(title='Number of rows in each of {} tests (for {} {}_row test) that their respective D_value is leass than D_critical for that specific test. <br>Mean = {}, min = {}, max = {}'.format(len(test_1.header),name, type_pick, np.mean(y_1), min(y_1), max(y_1)))
        fig_1 = go.Figure(trace, layout_1)
        fig_1.update_xaxes(title_text = 'Individual Tests')
        fig_1.update_yaxes(title_text = 'D_value')
        return fig_1

    elif plot_pick == 'ks':
        data = []
        for data_ in data_pick:
            path = data_ + '//' + type_pick.lower()+ '_test'
            name = data_
            test_1=test_stat(path, type_pick.lower())
            test_1.stat_test()
            ks_1 = test_1.ks_1
            D_crit_1 = test_1.D_crit_1  
            
            # df_1 = pd.DataFrame({'x': np.arange(1, len(ks_1)+1)/len(ks_1), 'y1': sorted([x[0][0] for x in ks_1])})
            # df_1_c = pd.DataFrame({'x': np.arange(1, len(ks_1)+1)/len(ks_1), 'y2': test_1.D_critical[0]})

            # fig_1 = intersection_point(df_1, df_1_c, type_pick)
            # fig_1.update_xaxes(title_text = 'Individual Tests')
            # fig_1.update_yaxes(title_text = 'D_value')
            # layout_1 = go.Layout(title='ks_test D_critical for {} for alpha = [0.01], #tests: {} for {}_test'.format(name, len(test_1.header), type_pick))
            # fig_1.layout = layout_1
            # self.ks = fig_1
            trace = [go.Scatter(x = np.arange(1, len(ks_1)+1)/len(ks_1), y = sorted([x[0][0] for x in ks_1]), mode ='lines+markers', name='KS_'+name)]
            data.append(trace)
        layout = go.Layout(title='ks_test D_value for {}, #tests: {} ({}_test)]'.format(name, len(test_1.header), type_pick))
        fig_ks = go.Figure(data, layout)
        fig_ks.update_xaxes(title_text = 'Individual Tests')
        fig_ks.update_yaxes(title_text = 'D_value')
        
        return fig_ks
        
        
    #AD test
    elif plot_pick == 'ad_row':
        data = []
        for data_ in data_pick:
            path = data_ + '//' + type_pick.lower()+ '_test'
            name = data_
            test_1=test_stat(path, type_pick.lower())
            test_1.stat_test()
            ad_1_row = test_1.ad_1_row 
            len_1 = len([x[0] for x in test_1.ad_row if 0.01<x[1]<0.99])
            trace = [go.Scatter(x = np.arange(1, len(ad_1_row)+1)/len(ad_1_row), y = sorted([x[1] for x in ad_1_row]), mode ='lines+markers', name='AD_'+name+' /{}'.format(len_1))]
            data.append(trace)
        layout = go.Layout(title='AD_test_row plot for {}, #tests: {} ({}_test)'.format(name, len(test_1.header), type_pick))
        fig_ad_row = go.Figure(data, layout)
        fig_ad_row.add_hline(y=np.mean([x[1] for x in ad_1_row]), line_width=1, line_dash="dash", line_color="red", annotation_text='mean_'+name, annotation_position="bottom right")
        fig_ad_row.add_hline(y=np.median([x[1] for x in ad_1_row]), line_width=1, line_dash="dash", line_color="orange", annotation_text='median_'+name, annotation_position="top right")
        fig_ad_row.update_xaxes(title_text = 'Individual rows')
        fig_ad_row.update_yaxes(title_text = '1-p')
        return fig_ad_row
    
    #collective
    elif plot_pick == 'ad':
        data = []
        for data_ in data_pick:
            path = data_ + '//' + type_pick.lower()+ '_test'
            name = data_
            test_1=test_stat(path, type_pick.lower())
            test_1.stat_test()
            ad_1 = test_1.ad_1
            p_tot_1 = test_1.p_tot
            trace = [go.Scatter(x = np.arange(1, len(p_tot_1)+1)/len(p_tot_1), y = sorted(p_tot_1), mode ='lines+markers', name='P_'+name+', AD = {}'.format(round(ad_1[1], 3)))]
            data.append(trace)
        layout = go.Layout(title='AD_test plot for {}, #tests: {} ({}_test)'.format(name, len(test_1.header), type_pick))
        fig_ad = go.Figure(data, layout)
        fig_ad.update_xaxes(title_text = 'Individual tests')
        fig_ad.update_yaxes(title_text = 'p_value (chi2)')
        return fig_ad


elif type_pick == 'F':
    #['chi', 'ks', 'ks_1',  'ad']
    #Chi
    if plot_pick == 'chi':
        data = []
        for data_ in data_pick:
            path = data_ + '//' + type_pick.lower()+ '_test'
            name = data_
            test_1=test_stat(path, type_pick.lower())
            test_1.stat_test()
            chi_1 = test_1.chi_1
            data = [go.Scatter(x = np.arange(1, len(chi_1)+1)/len(chi_1), y = sorted([x[0] for x in chi_1]), mode ='lines+markers', name='chi_'+name)]
        layout = go.Layout(title='chi_square for {}, #tests: {} ({}_test)'.format(self.name_1, len(test_1.header),self.type))
        fig_chi = go.Figure(data, layout)
        fig_chi.add_hline(y=np.mean([x[0] for x in chi_1]), line_width=1, line_dash="dash", line_color="red", annotation_text='mean_'+'{}'.format(self.name_1), annotation_position="bottom right")
        fig_chi.add_hline(y=np.median([x[0] for x in chi_1]), line_width=1, line_dash="dash", line_color="orange", annotation_text='median_'+'{}'.format(self.name_1), annotation_position="bottom left")
        fig_chi.update_xaxes(title_text = 'Individual Tests')
        fig_chi.update_yaxes(title_text = 'p_value')
        return fig_chi

    #KS
    elif plot_pick == 'ks_1':
        data = []
        for data_ in data_pick:
            path = data_ + '//' + type_pick.lower()+ '_test'
            name = data_
            test_1=test_stat(path, type_pick.lower())
            test_1.stat_test()
            ks_1 = test_1.ks_1
            D_crit_1 = test_1.D_crit_1  
    
            df_1 = pd.DataFrame({'x': np.arange(1, len(ks_1)+1)/len(ks_1), 'y1': sorted([x[0][0] for x in ks_1])})
            df_1_c = pd.DataFrame({'x': np.arange(1, len(ks_1)+1)/len(ks_1), 'y2': test_1.D_critical[0]})

            fig_1 = intersection_point(df_1, df_1_c, type_pick)
            fig_1.update_xaxes(title_text = 'Individual Tests')
            fig_1.update_yaxes(title_text = 'D_value')
        layout_1 = go.Layout(title='ks_test D_critical for {} for alpha = [0.01], #tests: {} for {}_test'.format(name, len(test_1.header), type_pick))
        fig_1.layout = layout_1
        return fig_1
    
    elif plot_pick == 'ks':
        data = []
        for data_ in data_pick:
            path = data_ + '//' + type_pick.lower()+ '_test'
            name = data_
            test_1=test_stat(path, type_pick.lower())
            test_1.stat_test()
            ks_1 = test_1.ks_1
            D_crit_1 = test_1.D_crit_1 
            data = [go.Scatter(x = np.arange(1, len(ks_1)+1)/len(ks_1), y = sorted([x[0][0] for x in ks_1]), mode ='lines+markers', name='KS_'+name)]
        layout = go.Layout(title='ks_test D_value for {}, #tests: {} ({}_test)]'.format(name, len(test_1.header), type_pick))
        fig_ks = go.Figure(data, layout)
        fig_ks.update_xaxes(title_text = 'Individual Tests')
        fig_ks.update_yaxes(title_text = 'D_value')
        fig_ks.add_hline(y=test_1.D_critical[0], line_width=1, line_dash="dash", line_color="red", annotation_text='0.01_'+name, annotation_position="bottom right")
        fig_ks.add_hline(y=test_1.D_critical[1], line_width=1, line_dash="dash", line_color="orange", annotation_text='0.05_'+name, annotation_position="bottom left")
        return fig_ks
    
    #AD
    elif plot_pick == 'ad':
        data = []
        for data_ in data_pick:
            path = data_ + '//' + type_pick.lower()+ '_test'
            name = data_
            test_1=test_stat(path, type_pick.lower())
            test_1.stat_test()
            ad_1 = test_1.ad_1
            data = [go.Scatter(x = np.arange(1, len(ad_1)+1)/len(ad_1), y = [ad_1[1]], mode ='lines+markers', name='AD_'+name+' AD = {}'.format(ad_1[1]))]
        layout = go.Layout(title='AD plot for {}, #tests: {} ({}_test)'.format(name, len(test_1.header), type_pick))
        fig_ad = go.Figure(data, layout)
        fig_ad.update_xaxes(title_text = 'Individual tests')
        fig_ad.update_yaxes(title_text = '1-p')
        return fig_ad
    
    
elif type_pick == 'M': 
    #['chi', 'ks', 'ks_1', 'ad']
    #chi
    if plot_pick == 'chi':
        data = []
        for data_ in data_pick:
            path = data_ + '//' + type_pick.lower()+ '_test'
            name = data_
            test_1=test_stat(path, type_pick.lower())
            test_1.stat_test()
            chi_1 = test_1.chi_1
            trace = [go.Scatter(x = np.arange(1, len(chi_1)+1)/len(chi_1), y = sorted([x[0] for x in chi_1]), mode ='lines+markers', name='chi_'+name)]
            data.append(trace)
        layout = go.Layout(title='chi_square for {}, #tests: {} ({}_test)'.format(name, len(test_1.header),type_pick))
        fig_chi = go.Figure(data, layout)
        fig_chi.add_hline(y=np.mean([x[0] for x in chi_1]), line_width=1, line_dash="dash", line_color="red", annotation_text='mean_'+name, annotation_position="bottom right")
        fig_chi.add_hline(y=np.median([x[0] for x in chi_1]), line_width=1, line_dash="dash", line_color="orange", annotation_text='median_'+name, annotation_position="bottom left")
        fig_chi.update_xaxes(title_text = 'Individual Tests')
        fig_chi.update_yaxes(title_text = 'p_value')
        fig_chi.update_xaxes(title_text = 'Individual n rows for each m test (total of nxm points)')
        return fig_chi

    #KS_plot     
    elif plot_pick == 'ks':
        data = []
        for data_ in data_pick:
            path = data_ + '//' + type_pick.lower()+ '_test'
            name = data_
            test_1=test_stat(path, type_pick.lower())
            test_1.stat_test()      
            ks_1 = test_1.ks_1
            D_crit_1 = test_1.D_crit_1  
            
            df_1 = pd.DataFrame({'x': np.arange(1, len(ks_1)+1)/len(ks_1), 'y1': sorted([x[0][0] for x in ks_1])})
            df_1_c = pd.DataFrame({'x': np.arange(1, len(ks_1)+1)/len(ks_1), 'y2': test_1.D_critical[0]})

            fig_1 = intersection_point(df_1, df_1_c, type_pick)
            fig_1.update_xaxes(title_text = 'Individual Tests')
            fig_1.update_yaxes(title_text = 'D_value')
        layout_1 = go.Layout(title='ks_test D_critical for {} for alpha = [0.01], #tests: {} for {}_test'.format(name, len(test_1.header), type_pick))
        fig_1.layout = layout_1
        return fig_1

        # data = [go.Scatter(x = np.arange(1, len(ks_1)+1)/len(ks_1), y = sorted([x[0][0] for x in ks_1]), mode ='lines+markers', name='KS_'+'{}'.format(self.name_1))]
        # layout = go.Layout(title='ks_test D_value for {}, #tests: {} ({}_test)]'.format(self.name_1, len(test_1.header), self.type))
        # fig_ks = go.Figure(data, layout)
        # fig_ks.up

Hi @tararu ,

=>
State('plot-picker', 'value')

‘options’ will pass in a list.

Thank you for your reply. Actually the State dcc is commented out, i am not using it in the code. I removed form the code above. sorry for the confusion.