mljar / mercury

Convert Jupyter Notebooks to Web Apps
https://RunMercury.com
GNU Affero General Public License v3.0
3.88k stars 244 forks source link

File upload widget not working inside loop #457

Open mr-easy opened 2 weeks ago

mr-easy commented 2 weeks ago

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.

pplonski commented 2 weeks ago

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?

mr-easy commented 2 weeks ago

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.