title: ggplot with customized font not showing properly on shinyapps.io
body: <p>I can customize the font in a <code>ggplot</code> with:</p>
  
  <pre><code>library(extrafont)
  
  windowsFonts()
  font_import(pattern = "comic", prompt = FALSE)
  loadfonts(device = "win")
  windowsFonts()
  
  ggplot(mapping=aes(x=seq(1,10,.1), y=seq(1,10,.1))) + 
    geom_line(position="jitter", color="red", size=2) + theme_bw() +
    theme(text=element_text(size=16,  family="Comic Sans MS"))
  </code></pre>
  
  <p>This renders as:</p>
  
  <p><a href="https://i.stack.imgur.com/IX1ky.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IX1ky.png" alt="enter image description here"></a></p>
  
  <p><em>More on the subject e.g. <a href="https://stackoverflow.com/questions/34522732/changing-fonts-in-ggplot2">here</a> and <a href="https://stackoverflow.com/questions/12675147/how-can-we-make-xkcd-style-graphs">here</a></em></p>
  
  <hr>
  
  <p>I can also integrate that plot and extrafont into a shiny app which runs locally as follows:</p>
  
  <pre><code>library(ggplot2)
  library(extrafont)
  library(shiny)
  
  font_import(paths = "www", pattern = "comic", prompt = FALSE)
  loadfonts()
  print(fonts())
  
  ui &lt;- fluidPage(plotOutput("plot"),textOutput("fonts"))
  
  server &lt;- function(input, output) {
     output$plot &lt;- renderPlot({
       ggplot(mapping=aes(x=seq(1,10,.1), y=seq(1,10,.1))) + 
         geom_line(position="jitter", color="red", size=2) + theme_bw() +
         theme(text=element_text(size=16,  family="Comic Sans MS"))
     })
     output$fonts &lt;- renderText(print(fonts()))
  }
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <hr>
  
  <p>However, when I try to deploy this to shinyapps.io I get an error:</p>
  
  <blockquote>
    <p>The application failed to start (exited with code 1).</p>
    
    <p>Registering fonts with R Scanning ttf files in www ... Extracting .afm
    files from .ttf files...
    /srv/connect/apps/21-comic-font/www/comici.ttfWarnung in gzfile(dest,
    "w")   kann komprimierte Datei
    '/opt/R/3.4.3/lib/R/library/extrafontdb/metrics/comici.afm.gz' nicht
    öffnen. Grund evtl. 'Permission denied' Fehler in value[3L] :
    kann Verbindung nicht öffnen Ruft auf: local ... tryCatch ->
    tryCatchList -> tryCatchOne ->  Ausführung angehalten</p>
  </blockquote>
  
  <hr>
  
  <p>I tried to solve this by incorporating the answer from <a href="https://stackoverflow.com/questions/51812219/using-custom-fonts-on-shinyapps-io#comment96844856_51812219">here</a>. I added my <code>.ttf</code> files to the <code>www</code> directory and the <code>extrafontdb</code> package source to the <code>r-lib</code> directory. (And of course I deployed both..).</p>
  
  <p>The complete <code>app.R</code> file now looks like:</p>
  
  <pre><code>.libPaths(c('r-lib', .libPaths()))
  install.packages('r-lib/extrafontdb_1.0.tar.gz',type = 'source',repos = NULL)
  
  library(ggplot2)
  library(extrafontdb)
  library(extrafont)
  library(shiny)
  
  font_import(paths = "www", pattern = "comic", prompt = FALSE)
  loadfonts()
  print(fonts())
  
  ui &lt;- fluidPage(plotOutput("plot"),textOutput("fonts"))
  
  server &lt;- function(input, output) {
    output$plot &lt;- renderPlot({
      ggplot(mapping=aes(x=seq(1,10,.1), y=seq(1,10,.1))) +
        geom_line(position="jitter", color="red", size=2) + theme_bw() +
        theme(text=element_text(size=16,  family="Comic Sans MS"))
    })
    output$fonts &lt;- renderText(print(fonts()))
  }
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>When I deploy this I get a running app and the following output:</p>
  
  <p><a href="https://i.stack.imgur.com/jf3cd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jf3cd.png" alt="enter image description here"></a></p>
  
  <p>Now the strange thing is, that <code>renderText(print(fonts()))</code> prints <em>Comic Sans MS</em>. So it <em>seems</em> that my font got loaded. But the plot does not show the proper font.</p>
  
  <p>Why is that? And how can I solve it?</p>