2 min read

Week43 - emoji

Week43 - emoji

This Week’s Widget - twemoji

For this week’s htmlwidget, all I needed was an excuse, and that excuse came in the form of a tweet by Jenny Bryan. Of course, we need an emoji htmlwidget. Since remoji already brings some emoji power to R, I thought I would try to piggyback on it and reduce the future number of R packages by at least 1. There are lots of very good JavaScript emoji libraries on Github. I chose twemoji from Twitter for my first round of experiments.

This needs help, so I’d love any help you can give in the form of feedback, ideas, feature requests, use cases, examples, …

Installation

This is not on CRAN and not even in the master branch, so to install we will need some help from devtools::install_github.

devtools::install_github("timelyportfolio/remoji@twemoji")

Examples

Examples this week are a little difficult, since emoji generally appear inline, and my blog setup doesn’t really like inline htmlwidgets. Here is a quick example from rmarkdown.

Know the Unicode

If you really love emoji, you might already know the unicode value for it.

#devtools::install_github("timelyportfolio/remoji@twemoji")

library(remoji)
library(stringi)
library(htmltools)

tagList(
  twemoji(svg = TRUE),
  tags$div(HTML("&#x1F4AA"),style="height:200px;width:200px")
)

Find with remoji

remoji offers the helpful find_emoji function so we don’t have to memorize unicode. I discovered the secret combination for use with htmltools. It looks like this HTML(stri_trans_general(emoji(flag),"any-hex/xml")).

#devtools::install_github("timelyportfolio/remoji@twemoji")

library(remoji)
library(stringi)
library(htmltools)

tagList(
  lapply(
    find_emoji("flag"),
    function(flag){
      tags$div(
        tags$p(
          style = "font-size:150%",
          flag,
          tags$span(
            HTML(stri_trans_general(emoji(flag),"any-hex/xml"))
          )
        )
      )
    }
  )
)

Thanks

Thanks Twitter for twemoji.

As always, thanks to

  • Ramnath Vaidyanathan and RStudio for htmlwidgets
  • all the contributors to R and JavaScript