Why won't my Greek letter (delta) show up in Shiny UNLESS it's within ggplot?

I have a piece of text that uses the Greek letter delta, and I want the text to be formatted with HTML in my Shiny app. Using unicode, this does not render correctly. However, doing this the same way but in a ggplot's title, it renders correctly.

How can I fix this?

Minimal Reprex:

library(shiny)
library(ggplot2)


ui <- fluidPage(
  
  htmlOutput("mytxt_WithHTML"), #Render the HTML text
  plotOutput("myplot", height="200px", width="500px")) #render plot

server <- function(input, output, session) {
  
  output$mytxt_WithHTML <- renderText({
    mytxt <- paste0("<b><center>Within renderText, the Greek letter delta appears as:",  "\u03b4", "</center></b>")#Can add "<br>" for line break 
    mytxt
  })
  
  output$myplot <- renderPlot({
    ggplot(mtcars, aes(x=mpg, y=cyl)) + geom_point() + ggtitle("Within a ggplot title, the Greek letter delta appears as: \u03b4")
  })
 
}
shinyApp(ui, server)

Result:
image

I found that I can get the delta to appear in the html by using &delta; or &#x3B4;

library(shiny)
library(ggplot2)


ui <- fluidPage(
  
  htmlOutput("mytxt_WithHTML"), #Render the HTML text
  plotOutput("myplot", height="200px", width="500px")) #render plot

server <- function(input, output, session) {
  
  output$mytxt_WithHTML <- renderText({
    mytxt <- paste0("<b><center>Within renderText, the Greek letter delta appears as:",  "&delta;", "</center></b>")#Can add "<br>" for line break 
    mytxt
  })
  
  output$myplot <- renderPlot({
    ggplot(mtcars, aes(x=mpg, y=cyl)) + geom_point() + ggtitle("Within a ggplot title, the Greek letter delta appears as: \u03b4")
  })
  
}
shinyApp(ui, server)
1 Like

Wonderful, this works for me thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.