Multi-text input is awkward with too much extra space

I’m trying to let the user enter a list of items to run a computation. This list can be variable in size, but I don’t want it to take the entire screen. This is what I’ve got so far:

import streamlit as st

st.title("A list!")
questions = [st.text_input("Enter your favorite things", "pizza")]
for n in range(5):
    questions.append(st.text_input(label='', key=f'Question {n}'))

I have to force a blank label and come up with a set key for each one of the questions. Even five items take up my entire screen! Looking at the html, it looks like it’s inserting an empty <label> element which creates the extra space. Removing this looks like

Which is much better for my use case. Is there a better way to do this, or is this not a supported feature?

Looking at it, I think if label is an empty string, not outputting a <label></label> html element would solve this. I can create a PR if there is interest!

1 Like

What about using text_area? A single box that allows for multiple lines to be input…

The problem with textarea is that each item is specific entry. If I used a textarea, I would have to manipulate the string coming out of it and hope that the user followed some instructions (like one line per entry). This seems more foolproof, but I’ll see if it works for my case.

Either way, a text_input with an empty label should not be putting in extra space. I can think of another use case where you might want a different item above it (like say a picture) and then the label space is sill superfluous.

I’m interested in this too. I have LaTeX, like $x_1$, written above my text_inputs, and then the label is blank. It creates an unaesthetic extra space.

1 Like

Did you manage to solve this problem? Could you advise a possible solution?

This problem still exists for me. Has anyone solved it?

Maybe you are looking for the label_visibility parameter of st.text_input.

import streamlit as st

st.title("A list!")
questions = [st.text_input("Enter your favorite things", "pizza")]
for n in range(5):
    questions.append(
        st.text_input(label=f'Question {n}', label_visibility="collapsed")
    )

Thank you! that solved my problem. I was not aware of the collapsed option for label_visibility, I was using “hidden” and that left lots of extra space.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.