Modify plotly chart based on different data through button click


I am trying to create a plotyly chart with some subplots based on Use button to filter different data in plotly python The chart generation function takes as input a stock symbol, dict of periods (m1, m3, m5… for different minutes) and stock specific period dataframes.

I am trying the put the periods as buttons, so that on a period button click, the corresponding dataframe (OHLC) can be loaded along with period dependent indicators - MACD, RSI and ADX.

The issue is only the last period df is loaded and the buttons are not showing/ loading the period specific OHLCV.

Below is the function

def plot_plotly_v3(in_stock, in_period_stock_mdf_df_dict,n):
    f_stock = in_stock
    f_period_stock_mdf_df_dict = in_period_stock_mdf_df_dict
    period_buttons = []
    i = 0
    period_length = len(f_period_stock_mdf_df_dict) # to calculate visible args
    period_frequency_dict = config.c_g_period_python_freq_dict # broker period to python period
    for period, stock_period_df in f_period_stock_mdf_df_dict.items():
        stock_period_df.index = stock_period_df.index.droplevel([1, 2])
        fig = make_subplots(rows=4, cols=1, shared_xaxes=True, vertical_spacing=0.007, row_heights=[.35, .20, .20, .25],
                            subplot_titles=('', 'MACD', 'RSI', 'ADX'))
        # removing all empty dates and build complete timeline from start date to end date
        py_frequency = period_frequency_dict.get(period) # broker period to python period mapping
        dt_all = pd.date_range(start=stock_period_df.index[0], end=stock_period_df.index[-1], freq=py_frequency)

        # retrieve the dates that ARE in the original datset
        dt_obs = [d.strftime("%Y-%m-%d %H:%M:%S") for d in pd.to_datetime(stock_period_df.index)]

        # define dates with missing values
        dt_breaks = [d for d in dt_all.strftime("%Y-%m-%d %H:%M:%S").tolist() if not d in dt_obs]
        in_period_int = int(config.g_period_2_period_int_dict.get(period))
        dvalue_ms = in_period_int * 60 * 1000
        fig.update_xaxes(rangebreaks=[dict(values=dt_breaks, dvalue=dvalue_ms)])
        fig_title = in_stock + ' for period ' + period + ' for range ' + 'From: ' + \
                    str(stock_period_df.index[0]) + ' To: ' + str(stock_period_df.index[-1])
        for annotation in fig['layout']['annotations']:
            annotation['textangle'] = -90
        fig.update_annotations(xshift=-620, yshift=-100)

        # Plot OHLC and MAs on 1st subplot    
        # Plot MACD trace on 2nd row    
        # Plot RSI trace on 3rd row
        # Plot ADX trace on 4th row
        # create visible args - True/ False list depending upon period/df dict
        visible_args = create_true_false_list_v0(i, period_length)
        # create a button object for the period we are on
        button = dict(label=period, method="update", args=[{"visible": visible_args}])

        # add the button to our list of buttons

        # i is an iterable used to tell our "args" list which value to set to True
        i += 1
    fig.update_layout(updatemenus=[dict(type="buttons",direction="right", x = 1,y = 1,buttons = period_buttons)],
                      height=800, width=1350, title=fig_title, xaxis_rangeslider_visible=False)

Would appreciate any support/ guidance.