I have to deploy a Dash App in a completely offline setting, and I’m having difficulty adding custom fonts. Can someone help me understand how I can use Open Sans? I downloaded a .zip file of the font files, extracted it to assets
and created a CSS file called open-sans.css
referring to the font files.
My project directory looks like:
assets/open-sans.css
assets/open-sans-v15-latin/open-sans-v15-latin-regular.eot
assets/open-sans-v15-latin/open-sans-v15-latin-regular.svg
assets/open-sans-v15-latin/open-sans-v15-latin-regular.ttf
assets/open-sans-v15-latin/open-sans-v15-latin-regular.woff
assets/open-sans-v15-latin/open-sans-v15-latin-regular.woff2
app.py
Code for assets/open-sans.css
:
/* open-sans-regular - latin */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: url('/assets/open-sans-v15-latin/open-sans-v15-latin-regular.eot'); /* IE9 Compat Modes */
src: local('Open Sans Regular'), local('OpenSans-Regular'),
url('/assets/open-sans-v15-latin/open-sans-v15-latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('/assets/open-sans-v15-latin/open-sans-v15-latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
url('/assets/open-sans-v15-latin/open-sans-v15-latin-regular.woff') format('woff'), /* Modern Browsers */
url('/assets/open-sans-v15-latin/open-sans-v15-latin-regular.ttf') format('truetype'), /* Safari, Android, iOS */
url('/assets/open-sans-v15-latin/open-sans-v15-latin-regular.svg#OpenSans') format('svg'); /* Legacy iOS */
}
Code for app.py
:
import dash
import dash_html_components as html
app = dash.Dash(__name__)
app.css.config.serve_locally = True
app.scripts.config.serve_locally = True
app.layout = html.Div(
[
html.H1(
'Hello World!',
style={
'textAlign': 'center',
'fontFamily': 'Open Sans',
}
),
],
)
if __name__ == '__main__':
app.run_server(debug=True)