This works if I put inside my UI:
library(shiny)
bslib::page_fluid(
tags$style(HTML("@font-face {
font-family: 'Hunger Games';
src: url('www/Hunger Games.ttf') format('truetype');
}"))
)
But this does not work:
library(shiny)
bslib::page_fluid(
theme = bs_theme(version = 5,
preset = "shiny",
heading_font = font_face(
family = 'Hunger Games',
src = "url('www/Hunger Games.ttf') format('truetype')"))
)
I found by using the inspector Tools. The app is looking for a file
Hunger Games-0.4.7/Hunger Games.ttf
, in the www subfolder. So you have to put your file Hunger Games.ttf in www/Hunger Games-0.4.7, and don't writewww/
inurl
. The 0.4.7 is the version of the sass package.This does not throw a 404 error:
EDIT
The above does not work in Shiny (or does not work at all, not sure...).
Now I've found how to do with Shiny. You have to add a resource path, for example you create a fonts subfolder in which you put the ttf file, and you use the
addResourcePath
function. This function requires a prefix, I takefonts
in the example below. Then you have to prefix the ttf file inurl
, like this:url('/myprefix/myfontfile.ttf')
.(Note that I removed the white space in your font file name, because I feared it could cause another difficulty; I didn't try with the white space.)