✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚾️ It's finally Baseball season! Root for the home team... & Register for our Sports Analytics Webinar!

Updating Callbacks for Changing HTML Elements

I am building a newsfeed type application where the elements are updated frequently through sql calls. The main page is a series of buttons each of which brings up a modal containing the contents of a news article. Once an article has been read it is removed, and a sql query is made to replenish the total number of articles. I have this working for the first article, however, once it has been removed and replenished none of the buttons respond. Is there a way to regenerate a callback everytime i replenish the html elements?

Build articles

def buildArticleTable(input):
    table = []
    for i in range(len(input)):
        if type(input.ix[i,'publish_date']) == None:
            date = ' | Date Published: Unknown'
        else:
            date = ' | Date Published: ' + input.ix[i,'publish_date']
        table.append(html.Div(className='row',children=[html.Button(input.ix[i,'title'],value = input.ix[i,'index'],className='row-title', id = 'button-{}'.format(input.ix[i,'index'])),
                                                                html.Label(html.A(input.ix[i,'source_url'],
                                                                                  href=input.ix[i,'url'],
                                                                                  style= {'margin':'0px 0px 0px 15px'}),
                                                                           className='row-extras'),
                                                                html.P(date, className = 'row-extras')]))

Original Callback Definition

              [button for i in strat.data['index'] for button in
               (Input('button-{}'.format(i), 'n_clicks_timestamp'), Input('button-{}'.format(i), 'value'))] +
              [Input('submit-article','n_clicks_timestamp'),
               Input('submit-article','value'),
               Input('close','n_clicks_timestamp'),
               Input('close','value')]
)
def show_modal(*args):
    print('In the Modal thing')
    dict = {}
    for time, value in zip(*[iter(args)]*2):
        print(time,value)
        if time != None:
            dict[time] = value
    if len(dict) > 0:
        latest = max(dict,key=int)
        if dict[latest] in ['submit-article','close']:
            print('Regarding The Modal this was pressed: ' + str(dict[latest]))
            return {'display':'none'}
        else:
            return {'display':'block'}```