Home > OS >  image titles do not render properly
image titles do not render properly

Time:03-18

I am trying to run the example shiny app (I added the options(encoding = 'UTF-8')):

options(encoding = 'UTF-8')

library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(
   
   # Application title
   titlePanel("Old Faithful Geyser Data"),
   
   # Sidebar with a slider input for number of bins 
   sidebarLayout(
      sidebarPanel(
         sliderInput("bins",
                     "Number of bins:",
                     min = 1,
                     max = 50,
                     value = 30)
      ),
      
      # Show a plot of the generated distribution
      mainPanel(
         plotOutput("distPlot")
      )
   )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
   
   output$distPlot <- renderPlot({
      # generate bins based on input$bins from ui.R
      x    <- faithful[, 2] 
      bins <- seq(min(x), max(x), length.out = input$bins   1)
      
      # draw the histogram with the specified number of bins
      hist(x, breaks = bins, col = 'darkgray', border = 'white')
   })
}

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

and the image has not encoded the names (titles).

enter image description here

UPDATE

I tried to use par(family ="Ubuntu Mono") in the R script and it works. But, it doesn't work in the shiny app (tried it inside render plot).

CodePudding user response:

This looks like a font conflict. You could circumvent it by setting a custom font available on your system that does get rendered correctly.

For base graphics, use par(family = "serif") or renderPlot(..., family = "serif") in Shiny. For ggplot2 graphics, set theme(text = element_text(family = "serif")) for an individual plot, or use base_family in supported themes, e.g. theme_gray(base_family = "serif").

In all of the above, replace "serif" with the font you want to use. For example, you specifically mentioned "Ubuntu Mono" rendering correctly in your case.

  • Related