I would like to change from the vertical input to column input using streamlit also, columns have to be dynamic


I would like to change the vertical number input to column number input

Steps to reproduce

Code snippet:

import numpy as np
import streamlit as st
st.header('Input Data')
p = np.array([[4,3,6,2],[1,4,3,5],[2,5,2,3],[5,2,4,1],[3,6,1,4]])
t = []
tb = len(p)
st.subheader('Enter the T value into row for multiplication')
for i in range(tb):
  value = st.number_input(f'row{i}:', min_value=0, max_value=10, step=1)
t = np.array(t)
t = np.tile(t, (p.shape[1], 1)).T 
p_mod = np.multiply(p, t)
st.header('Output Data')

Explain what you expect to happen when you run the code above.
Suppose If I run the above code I would get the number input in vertical order but I would like to have in horizontal order

Debug info

  • Streamlit version: 1.20.0
  • Python version: 3.9
  • Using Conda
  • OS version: WIndows 10

My output for the above program:

Use columns.

I tried, but it failed because I used a for loop in my program and had to specify the column size to be dynamic.

You can specify the number of columns.

but it had to be dynamic for my future work

Not sure what you mean by dynamic. If the number of columns changes, then the size of the columns will change too.

for the above program

cols = st.columns(len(p)) #len(p) is the column size

suppose if I add the another row in the input data p column size have to be increase automatically.

len(p) is the number of columns, not the column size.

If you add a row to p then len(p) will increase and the number of columns will increase too and the column size will decrease to accommodate more columns.