How to take Text Input from a user

Hi Team ,

The package looks great!. I wanted to know if there is a simple way to take a text input from the user and use the input to filter or create views on streamlit. Since there are many millions of data points , i am unable to use the slider or dropdown option for this

Thanks and regards,
Aravind

1 Like

Hi Aravind_K_R

There are two ways to get text input from users.

First, there’s st.text_input for when you only need a single line of text:

user_input = st.text_input("label goes here", default_value_goes_here)

Then there’s st.text_area for then you want multiple lines of text:

user_input = st.text_area("label goes here", default_value_goes_here)

In both cases, the default_value_goes_here argument is optional. You can find more about these in our API documentation.

Let me know if this answers your question!

4 Likes

Thank you for the prompt response. Will check it out :slight_smile:

1 Like

Hi all,
Has anyone successfully tried to use this input function to get the location of a file and use it to load data?
I’m a entering the location of the file in my system and using pandas to read the csv but I haven’t been able to see the data.
Thanks in advance

Hi @gabe_maldonado

That’s definitely possible!

Here’s an example that I just tested on my machine:

import streamlit as st
import pandas as pd

path = st.text_input('CSV file path')
if path:
    df = pd.read_csv(path)
    df

Then try a file like this one:

foo,bar,baz
1,2,3
4,5,6
7,8,9
4 Likes

Obrigado @thiago! Works like a charm. I appreciate the help.

GM

Update – This works perfect on the localhost. I am able to retrieve any dataframe from my machine and perform EDA. I deployed this to heroku but I am not able to access the files. I encounter a:
FileNotFoundError:[[Errno2] File 'bFileName does not exist
eda-st.herokuapp.com

Hi, I have been using Streamlit for a while. The text input package looks great. There is an issue I am running into. I have been using a text input in my app to ask the user for word input. The word they write is to get added to an already existing list. Now, once the word is added, and the user wants to input a new word, the previous word is getting removed from the list. Is there a way to make the text inputs from users permanent? Thanks in advance.

Hey , can this input method will also be used to take numbers as input and then perform some calculations on them after storing them in variable?

Not sure what you mean. Are you looking for st.number_input?

2 Likes

Yes thanks, got that

2 Likes

This is how you can get a Google Drive csv/excel share link to a Pandas DataFrame:

url = 'google share drive link'
path = 'https://drive.google.com/uc?export=download&id='+url.split('/')[-2]
outlet_df = pd.read_csv(path)

Hi @Daredevil_noob , have you found any solution to the problem?

Does anyone know how to mark a text input optional or compulsory?

How’s can we use label in streamlit?
question = "How could you elaborate NLP?" st.label("Question:-", question)

@toribi_Heppi

The label is the first argument you pass to each widget. For example:

st.text_input("How could you elaborate NLP?")
1 Like

@Sumit_Kumar

You could do something like this:

name = st.text_input("Enter your name (required)")

if not name:
  st.warning("Please fill out so required fields")
1 Like

Yes, I have to create with lots of frontend UI and text box. Do you know is there any template or tutorial is available?

Hey maybe a bit late, but I think you can append the variable of the text_input to the list in question.
Let me know if you need an example.
Good Luck!

def text_field(label, columns=None, **input_params):
    c1, c2 = st.columns(columns or [1, 4])

    # Display field name with some alignment
    c1.markdown("##")
    c1.markdown(label)

    # Sets a default key parameter to avoid duplicate key errors
    input_params.setdefault("key", label)

    # Forward text input parameters
    return c2.text_input("", **input_params)
    username = text_field("Questions:-",)
    # Notice that you can forward text_input parameters naturally
    answer= text_field(("Answer:-"))

I have this code and I want to increase the answer field area like text_area.
I tried it to write answer= st.text_area(text_field(("Answer:-"))) but does not work.

What shall I do for it?

Hello I used it. st.text_input but I want to saw jut question from backend, I will not give access to used edit the question.

Is there any other way to show just the question in the frontend. I mean, user will not edit the text_input field.