Creating multiple tables in a single callback function

I have a callback function that is supposed to write multiple tables by using a for loop, but somehow, only one of the tables gets produced:

def update_table(value, max_rows=100):
for key in returnrates[value]:
	return html.Table(
		# Header
		[html.Tr([html.Th(col) for col in returnrates[value][key].columns])] +

		# Body
		[html.Tr([
			html.Td(returnrates[value][key].iloc[i][col]) for col in returnrates[value][key].columns
		]) for i in range(min(len(returnrates[value][key]), max_rows))]
	)

I’d appreciate any thoughts on where I might be going wrong.

Happy Easter!

A return statement ends the execution of a function. You’re breaking out of the loop and returning the table on the first iteration of the for loop. You should put all of your tables inside a list or something and then return that.

1 Like

Thanks, I solved it exactly the way you suggested, with generating the tables with list.append(), then returning the list.