darkexodus
darkexodus

Reputation: 167

how to use a python variable inside streamlit markdown

  import streamlit as st
  statename = "some state name"
  d = 2000
  
  st.markdown("""
    #### "<span style="color:blue">{temp1}</span> has made {temp} calls".format(temp1 = statename, temp = str(d))    
  """,  unsafe_allow_html=True)

Here the .format is now working. The whole line is treated as a string.

Output: output

Any idea how to fix this?

Upvotes: 0

Views: 3738

Answers (1)

Baris Ozensel
Baris Ozensel

Reputation: 463

can you try "f" other than .format as following?:

f"""
  #### "<span style="color:blue">{temp1}</span> has made {str(d)} calls"  
"""

see the output below:

  #### "<span style="color:blue">some state name</span> has made 2000 calls"

using .format:

"""
  #### "<span style="color:blue">{}</span> has made {} calls"   
""".format(statename,str(d))

or

"""
  #### "<span style="color:blue">{temp1}</span> has made {temp} calls"   
""".format(temp1=statename,temp=str(d))

Upvotes: 2

Related Questions