Hi!
I run a deployed app from a private github repo and I am trying to add custom fonts (google and non-google fonts) to it. However, I need to serve the font via local files directly, since providing them via a google fonts api call causes GDPR problems and for the other fonts I just have the files. I’ve downloaded the respective .tff/.woff/.woff2 files and am now trying to include them but the font will not be updated.
My folder structure is:
.streamlit
static
fonts
----fira-sans-v17-latin-100.woff2
---- all other font styles / data formats
style.css
app.py
My style.css
looks like this:
h1 {
font-family: "Fira Sans";
font-style: normal;
font-weight: 100;
}
@font-face {
font-display: swap; /* Check https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display for other options. */
font-family: 'Fira Sans';
font-style: normal;
font-weight: 100;
src: url('../fonts/fira-sans-v17-latin-100.eot'); /* IE9 Compat Modes */
src: url('../fonts/fira-sans-v17-latin-100.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('../fonts/fira-sans-v17-latin-100.woff2') format('woff2'), /* Chrome 36+, Opera 23+, Firefox 39+, Safari 12+, iOS 10+ */
url('../fonts/fira-sans-v17-latin-100.woff') format('woff'), /* Chrome 5+, Firefox 3.6+, IE 9+, Safari 5.1+, iOS 5+ */
url('../fonts/fira-sans-v17-latin-100.ttf') format('truetype'), /* Chrome 4+, Firefox 3.5+, IE 9+, Safari 3.1+, iOS 4.2+, Android Browser 2.2+ */
url('../fonts/fira-sans-v17-latin-100.svg#FiraSans') format('svg'); /* Legacy iOS */
}
and in app.py
I am using the “css-hack”:
import streamlit as st
with open("style.css") as f:
st.markdown('<style>{}</style>'.format(f.read()), unsafe_allow_html=True)
st.title("This is a header")
However, just the font-weight and font-style render but not the font-family. I guess there might be a problem with the relative path but I cant figure it out. I also tried to move the style.css and the font files to the static folder but no success this way either…Additionally I tried to use streamlit.components html
import streamlit as st
import streamlit.components.v1 as components
components.html("""<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>This is a heading</h1>
</body>
</html>"""
but still the same problem. Does anybody have an idea on how to solve this?