Hi! I’d like to better understand if it’s possible to insert markdown into the help argument of a input widget, or if there’s feasible workarounds. My use case is that I’d like to format the help text with line breaks, and I’ve been unable to find any solutions as of now. Thanks!
What happened when you tried?
The input returns an error for: TypeError: expected string or bytes-like object
I wonder what you are actually trying. Just using markdown syntax in the help text shouldn’t cause that error. There must be something else going on.
help=st.markdown(‘## test’) is what I tried.
help keyword argument needs to be given a string, not a Streamlit command.
help_txt = ''' # This is a header This is plain text with some :red[color]. Check out [Streamlit](https://www.streamlit.io) ''' st.number_input('label',0,10,0,1, help=help_txt)
Note that color only works for Streamlit v1.16.0 that was released a few days ago, be sure to update if you want that.
Thank you very much! So the keyword argument only interprets line breaks specified as empty lines opposed to programmatically such as br, \n, etc. ?
Just follow markdown rules for line breaks.
One option is to end lines with two spaces.
''' There are two spaces at the end of this line. And this will render as a second line, even though it is right under the previous. '''
Thanks for the help, I was able to get the below working!
Cool. I was just writing up an explanation of string replacement. Even though you don’t need it, I’ll put it here in case it helps someone later:
import streamlit as st help_txt = '''This is a line And this follows a line break''' st.markdown(help_txt) bytes_help_txt = bytes(help_txt, 'utf-8') st.markdown(bytes_help_txt) new_line = ''' ''' mod_help_txt = help_txt.replace(new_line,' '+new_line) st.markdown(mod_help_txt) st.number_input('label',0,10,0,1, help=mod_help_txt)