mercury icon indicating copy to clipboard operation
mercury copied to clipboard

File upload widget not working inside loop

Open mr-easy opened this issue 1 year ago • 2 comments
trafficstars

I want to create multiple File upload widget, but it's creating just one widget when created inside a loop.

files = []
for i in range(4):
    files.append(mr.File(label="File upload "+str(i+1), max_file_size="100MB"))

This gives only one file widget 'File upload 4'

While this works:

files = []
files.append(mr.File(label="File upload "+str(1), max_file_size="100MB"))
files.append(mr.File(label="File upload "+str(2), max_file_size="100MB"))
files.append(mr.File(label="File upload "+str(3), max_file_size="100MB"))
files.append(mr.File(label="File upload "+str(4), max_file_size="100MB"))

But I want to do it in a loop.

mr-easy avatar Jul 10 '24 05:07 mr-easy

Hi @mr-easy,

Looks like we don't support creating file upload widgets in the loop, sorry. Here is docs for File widget https://runmercury.com/docs/input-widgets/file/ The File widget is missing url_key argument in constructor. Other widgets with url_key can be created in the loop https://runmercury.com/examples/create-widgets-in-loop/ I believe this can be fixed.

How many widgets would you like to create in the loop? What is your use case?

pplonski avatar Jul 10 '24 06:07 pplonski

I am creating a dashboard for stock market trade analysis. Now I want to give user the option to upload multiple files along with a multiplier for each file. So first I ask how many files needs to be uploaded, and then that many Fileupload widgets are created. Can range from 1 to 10.

mr-easy avatar Jul 10 '24 09:07 mr-easy