Create widgets in the loop

Create widgets in the loop

It is possible to create widgets in the loop. You need to set unique url_key for widgets created in the loop.

Required packages

You will need mercury package to run this example.


In the first cell, please import required packages:

import mercury as mr

Create widgets in the loop:

texts = []
for i in range(5):
    texts += [mr.Text(label=f"Widget {i}", value=f"{i}", url_key=f"w-{i}")]

Display widgets values:

for t in texts:

The notebook's code in the Jupyter Notebook:

Create widgets in the loop in Python notebook

Mercury App

Please start Mercury in the same directory as notebook:

mercury run

You will see the app running at Below is an animation with Mercury App:

Mercury App with widgets created in the loop

Notebook from this example is available in the mercury-examples (opens in a new tab) repository.