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
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!
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.
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.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.