Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FontAwesome icons specified as unicode not displayed properly #1611

Closed
nteetor opened this issue Mar 17, 2017 · 5 comments
Closed

FontAwesome icons specified as unicode not displayed properly #1611

nteetor opened this issue Mar 17, 2017 · 5 comments

Comments

@nteetor
Copy link

nteetor commented Mar 17, 2017

I stumbled across this issue when trying to specify a FontAwesome unicode string as an html tag data attribute.

The small shiny app below demos how icon("square-o") and a standard unicode symbol ♠ display properly, but a FontAwesome icon specified using unicode does not display correctly.

library(shiny)

shinyApp(
  ui = fluidPage(
    tags$ol(
      tags$li(
        icon("square-o")
      ),
      tags$li(
        ""
      ),
      tags$li(
        HTML("")
      ),
      tags$li(
        enc2utf8("")
      ),
      tags$li(
        HTML(enc2utf8(""))
      ),
      tags$li(
        HTML(enc2utf8("♠"))
      ),
      tags$li(
        HTML(enc2utf8("♠"))
      )
    )
  ),
  server = function(input, output, session) {
    
  }
)

The output:
screen shot 2017-03-17 at 11 18 03 am

See http://fontawesome.io/cheatsheet/ for fa-square-o unicode.

@jcheng5
Copy link
Member

jcheng5 commented Mar 17, 2017 via email

@jcheng5
Copy link
Member

jcheng5 commented Mar 17, 2017

@jcheng5 jcheng5 closed this as completed Mar 17, 2017
@nteetor
Copy link
Author

nteetor commented Mar 17, 2017

You are absolutely correct.

My example was not what I meant to put together. I think I was too deep in the weeds by that point.

The real problem, that I tried to abstract away in my first example application, is shiny does not seem to allow inclusion of FontAwesome icons through CSS attr() and tag data attributes. Here is an SO link better illustrating what I am trying to accomplish, http://stackoverflow.com/questions/34596056/how-to-use-data-attributes-with-font-awesome.

In shiny using a data attribute has not worked. Here is an updated example,

shinyApp(
  ui = fluidPage(
    tags$head(
      tags$style(".marked::before { font-family: FontAwesome; font-style: normal; content: attr(data-icon) }")
    ),
    tags$ol(
      tags$li(
        icon("square-o")
      ),
      tags$li(
        HTML("♠")
      ),
      tags$li(
        class = "marked",
        `data-icon` = HTML("")
      )
    )
  ),
  server = function(input, output, session) {
    
  }
)

screen shot 2017-03-17 at 5 53 21 pm

@jcheng5
Copy link
Member

jcheng5 commented Mar 17, 2017

Oh OK, that's fair. The reason is because the HTML tag functions always HTML-escape their attributes; HTML() is not respected for attributes. In this case, you can use a literal character instead:

`data-icon` = "\uf096"

@nteetor
Copy link
Author

nteetor commented Mar 18, 2017

Yes, this worked perfectly, thank you Joe. My apologies for this turning into more of a SO post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants