How do I install custom fonts in shinyapps.io apps (for base graphics, not html content)?

2,106 views
Skip to first unread message

Mark Riseley

unread,
Oct 1, 2015, 12:37:57 PM10/1/15
to ShinyApps Users
Is it possible to install a custom font eg Roboto to shinyapps.io apps?

I want to make base graphics with (client) custom font labels, so the font needs to be on the system and registered with R to be accessible.

I already tried extrafont::ttf_import() and that failed because it looks for a local path in the extrafontsdb and returns an error like the below (slightly edited for confidentiality) log output from shinyapps.io.

2015-10-01T16:27:55.604464+00:00 shinyapps[62561]: Registering fonts with R
2015-10-01T16:27:55.642720+00:00 shinyapps[62561]: Scanning ttf files in /srv/connect/apps/my_test_app/www/fonts/ ...
2015-10-01T16:27:55.643122+00:00 shinyapps[62561]: Extracting .afm files from .ttf files...
2015-10-01T16:27:55.722440+00:00 shinyapps[62561]: /srv/connect/apps/my_test_app/www/fonts/my_custom_font/my_custom_font_bold-webfont.ttfWarning in gzfile(dest, "w") :
2015-10-01T16:27:55.722442+00:00 shinyapps[62561]:   cannot open compressed file '/usr/local/lib/R/site-library/extrafontdb/metrics/my_custom_font_bold-webfont.afm.gz', probable reason 'Permission denied'
2015-10-01T16:27:55.722918+00:00 shinyapps[62561]: Error in gzfile(dest, "w") : cannot open the connection

Yihui Xie

unread,
Oct 1, 2015, 1:10:54 PM10/1/15
to Mark Riseley, ShinyApps Users
One trick is to install the font to ~/.fonts since ShinyApps.io uses
Ubuntu. You may download the fonts to ~/.fonts and run fc-cache -f in
that directory.

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Web: http://yihui.name
> --
> You received this message because you are subscribed to the Google Groups
> "ShinyApps Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to shinyapps-use...@googlegroups.com.
> To post to this group, send email to shinyap...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/shinyapps-users/6c25fa11-04a0-4601-b7a7-29111c865eaa%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Mark Riseley

unread,
Oct 1, 2015, 1:19:29 PM10/1/15
to Yihui Xie, ShinyApps Users
That sounds helpful but could you please spell out the steps to make it work for a shinyapps.io app?

I'm a Windows user, and I can't create a folder called ".fonts" in my application directory, or call fc-cache -f.

Do I need some kind of script file to execute this process, and if so where do I put it and how do I invoke it?

Thanks!

Yihui Xie

unread,
Oct 1, 2015, 7:20:03 PM10/1/15
to Mark Riseley, ShinyApps Users
Sure. Basically the steps look like this:

1. dir.create('~/.fonts')
2. Download the fonts, e.g. via download.file(), to ~/.fonts
3. Run system('fc-cache -f ~/.fonts')

You probably only want to do this when Sys.info()[['sysname']] ==
'Linux' since this does not make sense to Windows.

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Web: http://yihui.name


Mark Riseley

unread,
Oct 2, 2015, 6:51:33 AM10/2/15
to Yihui Xie, ShinyApps Users
Thanks Yihui, this worked a charm!

Reply all
Reply to author
Forward
0 new messages