r-lib/ragg

ragg/emojis Won't Render on Deployed Products

Closed this issue ยท 3 comments

rsh52 commented

Hello!

Background

I am working on a ggplot2-based package where I want users to be able to paste emojis as label options directly into function arguments for the rendered output.

Issue

I have found ragg is the best way to easily get emojis to render locally, but am having trouble with any deployed products (RMDs and shiny applications) on both shinyapps.io as well as our Posit Connect instance. I have tried viewing the outputs in both Google Chrome and Safari. Session info posted below:

Session Info
> sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS 13.4

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] dplyr_1.1.2   ragg_1.2.5    ggplot2_3.4.2 shiny_1.7.4.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.11       compiler_4.2.0    pillar_1.9.0      bslib_0.5.0       later_1.3.1       jquerylib_0.1.4   tools_4.2.0      
 [8] digest_0.6.33     memoise_2.0.1     jsonlite_1.8.7    lifecycle_1.0.3   tibble_3.2.1      gtable_0.3.3      pkgconfig_2.0.3  
[15] rlang_1.1.1       rstudioapi_0.15.0 cli_3.6.1         curl_5.0.1        fastmap_1.1.1     withr_2.5.0       askpass_1.1      
[22] generics_0.1.3    vctrs_0.6.3       sass_0.4.7        systemfonts_1.0.4 tidyselect_1.2.0  grid_4.2.0        glue_1.6.2       
[29] R6_2.5.1          textshaping_0.3.6 fansi_1.0.4       farver_2.1.1      magrittr_2.0.3    scales_1.2.1      promises_1.2.0.1 
[36] ellipsis_0.3.2    htmltools_0.5.5   rsconnect_0.8.29  mime_0.12         xtable_1.8-4      colorspace_2.1-0  renv_0.16.0      
[43] httpuv_1.6.11     labeling_0.4.2    utf8_1.2.3        openssl_2.1.0     munsell_0.5.0     cachem_1.0.8      crayon_1.5.2     

Things I have tried:

  • Specifying "AGG" as the backend graphics device in the RStudio IDE options
  • Inserting a library(ragg) call in the shiny app
  • Adding options(shiny.useragg = TRUE) to the .Rprofile in the shiny app
  • Adding knitr::opts_chunk$set(echo = TRUE, dev='ragg_png') to the RMD (only applicable to Posit Connect)

shinyapps.io Output:
image

Posit Connect Output:
image

Local Output (desired):
image

Examples

Below are links to the applicable code and shareable application.

The Shiny App Code
library(shiny)
library(ggplot2)
library(ragg)
library(dplyr)

ui <- fluidPage(
  
  # Application title
  titlePanel("Sample Emoji Plot"),

  sidebarLayout(
    sidebarPanel(
      checkboxGroupInput(
        inputId = "types",
        label = "Types",
        choices = c("๐Ÿˆ", "๐Ÿ•"),
        selected = c("๐Ÿˆ", "๐Ÿ•")
      )
    ),
    mainPanel(
      plotOutput("emojiPlot")
    )
  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
  
  output$emojiPlot <- renderPlot({
    df <- data.frame(
      time = c(1, 2, 3, 4, 5),
      value = c(10, 15, 5, 30, 35),
      type = c("๐Ÿˆ", 
               "๐Ÿ•",
               "๐Ÿ•",
               "๐Ÿˆ",
               "๐Ÿˆ")
    )
    
    df |> 
    dplyr::filter(type %in% input$types) |> 
    ggplot(aes(x = time, y = value)) + 
      geom_label(aes(label = type)) +
      theme_minimal()
  })
}

# Run the application 
shinyApp(ui = ui, server = server)
rsh52 commented

Seeing as this repo hasn't seen much activity recently, tagging some authors @thomasp85 @jeroen

jeroen commented

The shinyapps output seems to work at least? Emojis look different on any platform. Because the server has different emoji fonts from what you have locally, you get a different ๐Ÿˆ glpyh in the ggplot2 image that is rendered on the server than what you see locally. But it certainly looks like a cat emoji.

To get nicer emojis in ragg, one could try to install the noto-color-emoji font on the server in a place where fontcontconfig can find it. The sysadmin could try apt-get install fonts-noto-color-emoji, then it looks like this:

noto

However note that they emoji rendered in the shiny menu will always be different than the one in the ggplot, because one is uses fonts from the client (browser ) and the other from R on the server. Perhaps if you really wanted to, you could also try to load and use the noto font family on the front-end side in your shiny app.

rsh52 commented

Hi @jeroen, I asked our Posit Connect system admin to install fonts-noto-color-emoji and that did in fact get it working for us. Now a few of our apps which previously had blank boxes show the intended emojis. Thank you!