Pass information from server side using uplink

Hello,

I am calling a function from Anvil using uplink that read(process) each row in an excel file and I count the processed one using:

while count<rows:
....process row
count=+count
num = f'Total rows processed {count}'
print(num)

What I want is to pass and to display this information (num) into a label in client side in Anvil while the function is running, to update the user what is current number of processed rows.

Thank you

I would use a background task to run this function, since you can update the ā€˜statusā€™ of the function of a running task, and that information can be accessed by using the task object that is created.

I would then use a Timer component of a form to check this background tasks status periodically (seconds, minutes, whatever) and have it update the text of your label on the page if the status has changed.

1 Like

I was thinking something more easier because the information to display is in:
num = f'Total rows processed {count}'
print(num)
each time the row is processed I have print(num) updated. I just want something like
self.label_1.text = num on client side to display this update.

Thank you

I understand, however you basically have two different processes running. You have your excel file processing, and you have a client browser running somewhere else. (even if you are doing both on the same computer for testing, you are connecting to anvil in-between)

If you think about it, how would you tell some random persons browser running your website code on their own computer to change something on their screen?
One easy way is to put the information in a mutually accessible place and have the persons browser check periodically for an update. (computers donā€™t really do well with the request ā€œplease check to see if a string changed an infinity number of times ASAPā€ )

I think javascript has ways that seem like they get around this, but I am pretty sure they are just obfuscating the same thing happening with a built in method. I am no javascript developer by any means so donā€™t quote me on that.

There are less-advanced ways to do what you want (from a learning anvil point of view), but they are not really simpler and require more python code than using what anvil has created for you with background tasks.

1 Like