Text_input

Hi- I have created simple text input but unable to render the assigned variable

exp_id = st.text_input(“Please experiment_id”, “”, key=“1”)

def vals(e):
print(e)

vals(exp_id)
** Throws ‘exp_id’ not defined . Please need your input on how to resolve

Hi @Bharat_koti,

Thanks for posting!

exp_id won’t be defined if there isn’t any input in the text input box.

You can add an if statement to check that st.text_input is defined.

exp_id = st.text_input(“Please experiment_id”, “”, key=“1”)

def vals(e):
   print(e)

if exp_id:
   vals(exp_id)

Caroline :balloon:

Hi @Caroline Thanks so much for responding.
I am entering the value in webpage, press enter and trying to assign back to the variable ‘exp_id’.
Initially that text box will be empty, user enters the text and I am trying pass that text to another function.

Hi @Bharat_koti,

It sounds like what I suggested above would work for that. Are you running into an error still?

Caroline :balloon:

Hi @Caroline That works - Thanks so much for the inputs.

Thanks,
Bharat

1 Like

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