hrbrthemes icon indicating copy to clipboard operation
hrbrthemes copied to clipboard

RC font not rendering in shiny

Open PaulC91 opened this issue 7 years ago • 7 comments

I have a shiny app with Roboto Condensed being the primary font. It links to a CSS stylesheet with the appropriate RC google fonts URL imported in:

@import url('https://fonts.googleapis.com/css?family=Roboto+Condensed');

It works on all <h> and <p> elements in the app but a ggplot with the ipsum_rc theme set is not rendering the rc font.

You can see the app here. and source code here.

Thanks!

PaulC91 avatar May 19 '17 10:05 PaulC91

I had a similar issue but I was able to find a workaround by importing CSS in the body element

body <- dashboardBody(tags$head( includeCSS(path = "www/styles.css") ), .... )

and my styles.css file is as following:

@import url('//fonts.googleapis.com/css?family=Roboto+Condensed:400,700');

oneryalcin avatar Nov 09 '17 10:11 oneryalcin

@oneryalcin Can you provide code that can reproduce ggplot successfully rendering RC in a Shiny app? I have tried all the CSS tricks and hacks. I have RC displaying correctly without a problem in the app, including body plus other packages (rbokeh, dygraphs etc.), but not in ggplot.

ciflikli avatar Dec 22 '17 00:12 ciflikli

I’m not a CSS or ggplot2 expert but I think the issue is that ggplot2 renders images not html. So we need to figure out how to get the ggplot to use the imported google RC font prior to rendering the image. May need be installed onto the Linux server prior to app loading?

PaulC91 avatar Dec 22 '17 01:12 PaulC91

@PaulC91 ggplot definitely seems to produce images that later get embedded, yes. On the Linux server part, I tried the following after seeing Yihui's post somewhere (Google groups?), but it didn't have an effect.

if (Sys.info()[["sysname"]] == "Linux") {

dir.create("~/.fonts") 
download.file("https://fonts.googleapis.com/css?family=Roboto+Condensed", "~/.fonts")
system("fc-cache -f ~/.fonts") 

}

Edit: Found the link, actually Julia Silge recommended this

ciflikli avatar Dec 22 '17 01:12 ciflikli

I'll be poking at this over the Christmas break, here. I'll embed an example shiny app in the pkg once i get it working.

hrbrmstr avatar Dec 22 '17 01:12 hrbrmstr

Oh nice - is it going to be something along the lines of #5? That sounds like a neat trick.

ciflikli avatar Dec 22 '17 07:12 ciflikli

Found a workaround! Blog post

Add this to global.R

require(showtext)
font_add_google(name = "Roboto Condensed", family = "Roboto Condensed",
regular.wt = 400, bold.wt = 700)
showtext_auto()
showtext_opts(dpi = 112)

Link to app

ciflikli avatar Dec 22 '17 08:12 ciflikli