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

Why html.Audio plays only the first time the callback is called?

I’m writing a dashboard to follow some information on task management of company employees. It’s a pretty simple dashboard and I organized it in way that each employee has a “card” to display these informations.

Each card has 4 possible “states”: 1) Not working, 2) Problem , 3) Alert and 4) OK. The program checks the informations to decide which state the user is every 10 minutes.

If the card was set to the third state, the dashboard is supposed to play an audio. However, this only happen when the card switch from the states 1, 3, or 4 to state 2. Which means that the audio won’t play if the user stay in state 2 for more than one “reload” in a row. For example: if a user stays with “Problem” for 30 minutes, it’ll play the audio once instead of three times. Below is the part of the code that (I think) matters.

def set_card_infos(user, row, col):	
    parent_div_style, text_style, percentage_style, task_text_style, project_text_style = config.get_styles(row, col)
	users_infos = UserInfos(user)
	percentage, paused_cycles, many_activities, working_task, working_project = users_infos.get()

	if not users_infos.is_working(): #State 1) Not working
		status_text_html = html.P('User is not working...', style=text_style)
		parent_div_style['background-color'] = config.NOT_WORKING_COLOUR
		return status_text_html, task_text_html, working_project_html, percentage_html, parent_div_style, [], 0

	elif paused_cycles: #State 2) Problem
		status_text_html = html.P(f'User is not working for {10*paused_cycles} minutes!', style=text_style)
		parent_div_style['background-color'] = config.PROBLEM_COLOUR
		audio_html = [html.Audio(src='https://docs.google.com/uc?export=download&id='+config.audio_files[user]['file_id'], autoPlay=True, controls=False)]
		audio_length = config.audio_files[user]['length']
		return status_text_html, task_text_html, working_project_html, percentage_html, parent_div_style, audio_html, audio_length
    
    elif 100 < percentage < 80: #State 3) Alert
		status_text_html = html.P(config.ALERT_TEXT, style=text_style)
		parent_div_style['background-color'] = config.ALERT_COLOUR
		return status_text_html, task_text_html, working_project_html, percentage_html, parent_div_style, [], 0
    
    status_text_html = html.P('All cool!', style=text_style) #State 4) OK
    return status_text_html, task_text_html, working_project_html, percentage_html, parent_div_style, [], 0

@app.callback([Output('conditional-text-user1', 'children'),
			   Output('task-user1', 'children'),
			   Output('project-user1', 'children'),
			   Output('percentage-user1', 'children'),
			   Output('card-user1', 'style'),
			   Output('audio-user1', 'children'),
			   Output('sleep-user-2', 'value')],
              [Input('reload-date', 'n_intervals')])
def update_infos_user1(n):
	return set_card_infos('user1', 1, 1)

@app.callback([Output('conditional-text-user2', 'children'),
			   Output('task-user2', 'children'),
			   Output('project-user2', 'children'),
			   Output('percentage-user2', 'children'),
			   Output('card-user2', 'style'),
			   Output('audio-user2', 'children'),
			   Output('sleep-user3', 'value')],
              [Input('sleep-user2', 'value')])
def update_infos_user2(wait):
	sleep(wait)
	return set_card_infos('user2', 1, 2)

"""
Remaining users
        .
        .
        .
"""

If I check inside the callback, the variable audio_html appears propperly… Anyone knows what might be causing this problem (i.e the absence of audio in the dashboard if the state remains the same)?