Actually I am getting used to streamlit but there is on thing I still havent understood. I have written a code in which the data is displayed in multiline format. For that I used the fstring.
But as you can see in the last some of the text is outside the gray box, how should I bring that in.
My code"-
import streamlit as st
import pandas as pd
import warnings
warnings.filterwarnings('ignore')
with st.sidebar:
uploaded_file = st.file_uploader('Upload the Final Annotation File')
exomeDf = pd.read_csv(uploaded_file,sep="\t")
st.write('Primary Variants')
pVariants = st.text_area('Enter the Chr_Position')
h = exomeDf[exomeDf.Chr_Position.str.contains(pVariants)]
d = h.to_dict(orient='records')[0]
l = "\n".join(d['MIM_disease_Name'].split(";"))
annoDescription = f'''
\n Variants Details \n
{d['Gene_symbol']} ({d['Inheritance']})
{d['canonicalCodon']} - {d['Zygosity']}
DP :- {d['DP']} ({d['AD']}) {d['Alt_Allele_Percent']}
ACMG :-
gnomAD_MAF(%) :- {f"{d['gnomAD_MAF(%)']}" if f"{d['gnomAD_MAF(%)']}" != "." else "NA"}
1000G_MAF(%) :- {f"{d['1000G_MAF(%)']}" if f"{d['1000G_MAF(%)']}" != "." else "NA"}
ClinVar :- {d['ClinVar_annotation']}
Franklin :-
SIFT :- {f"{d['SIFT_score']}" if f"{d['SIFT_score']}" != "." else "NA"}
MT :- {f"{d['MutationTaster_score']}" if f"{d['MutationTaster_score']}" != "." else "NA"}
PolyPhen2 :- {f"{d['Polyphen2_HDIV_pred']}" if f"{d['Polyphen2_HDIV_pred']}" != "." else "NA"}
MCAP :- NA
{l}
'''
st.write(annoDescription)
If I make any changes in the fstring like removing the \n Variants Details \n line, the whole display changes
I want all the text in that gray box so that I can copy the whole text with that copy icon in the top right corner. Am i making any mistake in the fstring. I tried using st.markdown too but that also didn’t worked.
Hi @Nikhil_Panchal ,
is this possible the issue you’re facing?
opened 07:01PM - 18 Dec 19 UTC
enhancement
st.markdown
This isn't a bug, but rather a potential source of confusion. (I was confused, a… t least.)
In markdown, if you want a newline in your text, simply putting a newline character in is not enough. You have to put two whitespace characters at the end of the previous line.
```python
import streamlit as st
st.write("Not multi-\nline")
st.write("Still not multi- \nline")
st.write("Ok now it's multi- \nline")
```
Apparently [this is part of the spec](https://markdown-guide.readthedocs.io/en/latest/basics.html#line-return), so maybe we shouldn't do anything here. But it seemed confusing enough to be worth noting.
Hi @willhuang , thank you That helped a little
But still those text are not coming inside the block. I made the changed like the following
l = d['MIM_disease_Name'].replace(";"," \n")
annoDescription = f'''
\n Variants Details \n
{d['Gene_symbol']} ({d['Inheritance']})
{d['canonicalCodon']} - {d['Zygosity']}
DP :- {d['DP']} ({d['AD']}) {d['Alt_Allele_Percent']}
ACMG :-
gnomAD_MAF(%) :- {f"{d['gnomAD_MAF(%)']}" if f"{d['gnomAD_MAF(%)']}" != "." else "NA"}
1000G_MAF(%) :- {f"{d['1000G_MAF(%)']}" if f"{d['1000G_MAF(%)']}" != "." else "NA"}
ClinVar :- {d['ClinVar_annotation']}
Franklin :-
SIFT :- {f"{d['SIFT_score']}" if f"{d['SIFT_score']}" != "." else "NA"}
MT :- {f"{d['MutationTaster_score']}" if f"{d['MutationTaster_score']}" != "." else "NA"}
PolyPhen2 :- {f"{d['Polyphen2_HDIV_pred']}" if f"{d['Polyphen2_HDIV_pred']}" != "." else "NA"}
MCAP :- NA
\n{l} \n'''
st.markdown(annoDescription)
What if you put “```” at the beginning and end of your annoDescription string?
so it would end up being:
f’‘’
\n Variants Details \n
```
{d[‘Gene_symbol’]} ({d[‘Inheritance’]})
{d[‘canonicalCodon’]} - {d[‘Zygosity’]}
DP :- {d[‘DP’]} ({d[‘AD’]}) {d[‘Alt_Allele_Percent’]}
ACMG :-
gnomAD_MAF(%) :- {f"{d[‘gnomAD_MAF(%)’]}" if f"{d[‘gnomAD_MAF(%)’]}" != “.” else “NA”}
1000G_MAF(%) :- {f"{d[‘1000G_MAF(%)’]}" if f"{d[‘1000G_MAF(%)’]}" != “.” else “NA”}
ClinVar :- {d[‘ClinVar_annotation’]}
Franklin :-
SIFT :- {f"{d[‘SIFT_score’]}" if f"{d[‘SIFT_score’]}" != “.” else “NA”}
MT :- {f"{d[‘MutationTaster_score’]}" if f"{d[‘MutationTaster_score’]}" != “.” else “NA”}
PolyPhen2 :- {f"{d[‘Polyphen2_HDIV_pred’]}" if f"{d[‘Polyphen2_HDIV_pred’]}" != “.” else “NA”}
MCAP :- NA
\n{l} \n
```‘’’
?
Now it is displaying that backticks
hi @willhuang , I found a solution
I used st.code instead of st.write
Now the box looks like this
Great! I was actually going to suggest that right after haha but i happened to go to sleep! Happy streamlitting!