St.text_input and special characters

Hi,

I am trying to build a text input field so that users can give values for API filter / query.
However, it seems that st.text_input (and also st.text_area) does not return special characters like “:”, for ex "dataField:eq=value" returns

"dataField
=value"

so loosing totally “:eq”

Is it somehow possible to get the value that is using some special characters?
Using HTML input?

Streamlit 1.27.2, python 3.11.4

Hi @JakeB,

The issue you’re encountering seems unusual. By default, st.text_input and st.text_area in Streamlit should handle special characters without any problems.

Could you please share the code with us?

Thanks,
Charly

Hi,

I looked at it more closely, and it seems that using st.write is the problem, it will not show all characters. Input text was ok when I just used print(), please see code and output below

fq_text = st.text_input('filter or query')
if fq_text:
    st.write('The current movie title is', fq_text)
    print("FQ_TEXT: ", fq_text)
fq_area = st.text_area('filter or query')
if fq_area:
    st.write('The current movie title is', fq_area)
    print("FQ_AREA: ", fq_area)

Output in console:

FQ_TEXT:  ?filter=externalId:eq=C7FED24F-7662-ED11-A6F9-000D3ADC5CA899999
FQ_AREA:  ?filter=externalId:eq=C7FED24F-7662-ED11-A6F9-000D3ADC5CA8zzzz

Output in browser:

image

You may want to try st.markdown, as it can render strings and might handle special characters better than st.write.

And, if that’s a valid option for you, you can either escape these characters via Python’s re library.

Let me know if that sorts your issue.

Best,
Charly

Thank you @Charly_Wargnier

I think we can close this, I know the reason and some options how to deal with this if needed.

1 Like

Glad it helps!

Best wishes,
Charly

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