St.metric error

Hi, I wonder if anyone can help me with this:

  1. I have 2 lists: header list (shdr) and data list (sdta), which are created dynamically (so I know their length only at runtime)
  2. I have an expander, into which I create a dynamic set of columns (equal to the length of any of the above lists)
  3. With the following code, I print out my metrics in each column (header and value)
  4. The following code works fine for this purpose:

with st.expander(“Examination Data:”, expanded = True): # dynamic beta cols
collst = st.columns(len(shdr)) # create dynamic number of cols
for i, vcol in enumerate(collst):
vcol.write(shdr[i]) # write heading of metric
vcol.write(sdta[i]) # write value of metric

Using the new streamlit release, I tried to do the following:

with st.expander(“Examination Data:”, expanded = True): # dynamic beta cols
collst = st.columns(len(shdr)) # create dynamic number of cols
for i, vcol in enumerate(collst):
vcol.write(st.metric(label = shdr[i], value = str(sdta[i])))

The metrics printed in a single column and I got this error:
DeltaGenerator(_root_container=0, _provided_cursor=LockedCursor(_root_container=0, _index=1, _parent_path=(3,), _props={‘delta_type’: ‘metric’, ‘last_index’: None}), _parent=DeltaGenerator(_root_container=0, _provided_cursor=RunningCursor(_root_container=0, _parent_path=(3,), _index=2), _parent=DeltaGenerator(_root_container=0, _provided_cursor=None, _parent=None, _block_type=None, _form_data=None), _block_type=‘expandable’, _form_data=FormData(form_id=’’)), _block_type=None, _form_data=None)

What am I doing wrong?

Have you tried the following?

for i, vcol in enumerate(collst):
    vcol.metric(label = shdr[i], value = str(sdta[i]))

Awesome @snehankekre, your suggestion worked. Thank you very much. :slight_smile: