Do you use st.text?

Do you use st.text? Why not st.write, st.markdown, or st.code?

(Don’t ask why I’m asking this! I’ll let you know soon, but for now I just want to get some responses before I bias you with my thinking! :wink:)

1 Like

Hi @thiago ,

I actually never use st.text, only st.markdown and st.caption.

Sometimes st.write, although I understand it is mostly a flexible “catch-all” method.

Almost never… #st.writeTeam

1 Like

I don’t think I’ve ever used st.text either. I always for for write, markdown, and code as fit for purpose.

1 Like

I use it to display the output of terminal commands. That output doesn’t have a particular color scheme, so I just go with st.text, instead of st.code (which adds colors) or st.write (which assumes it’s just a regular markdown block).

st.text :grin:
image

st.write :cry:
image

st.code :unamused:
image


is ASCII art a thing?

image

Source: ASCII Art Cars - asciiart.eu

3 Likes

So the only difference between st.text and st.code with the keyword language=None is that the secondary background color used?

import streamlit as st

terminal = '''

  You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8502
  Network URL: http://10.10.10.10:8502
'''

st.text(terminal)
st.code(terminal)
st.code(terminal, language=None)

image

how did I missed that :sweat_smile:

You’re right, there seems to be no other difference other than that secondary background.

1 Like

Ok, so here’s why I’m asking: there’s currently no way to write pure text in normal font in Streamlit.

To address this, we’ve floated a few types of solutions:

Idea 1: Add a new text command, like st.plaintext(mytext). (Name TBD)

Idea 2: Change st.text(mytext) so it uses normal font, and…

  • Idea 2a: …add an argument like st.text(mytext, style="preformatted") to switch to mono+preformatted text. (Again, details TBD)

    or

  • Idea 2b: …add a command for mono+pre text, like st.preformatted_text(mytext)

    or

  • Idea 2c: …don’t add any command for mono+pre text. Instead, just point people to st.code.

Thoughts?

1 Like

I vote 2a. While I still see st.code as my primary go-to for mono font because I usually want that secondary background color and like the copy widget, I think it’s nice to not preclude writing mono font directly onto the primary background. Adding a style optional keyword with mono default makes it a non-breaking change.

1 Like

Thats a useful comparison thanks

Never used st.text. I only use st.markdown for hiding, st.write for text, and st.latex for LaTeX.

Thanks all! I’ll share this with the team. Very helpful :pray:

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