rstudio / shiny

Easy interactive web applications with R
http://shiny.rstudio.com
Other
5.34k stars 1.87k forks source link

renderPlot cannot displayed Japanese multibyte characters #1923

Open manabet opened 6 years ago

manabet commented 6 years ago

Hi, we tried to display Japanese characters into renderPlot title or axis labels. But it didn't work. Only Japanese characters were missing in strings like below.

renderplot

But when we saved this figure as png file in server function, the Japanese character was displayed successfully.
(so renderImage and imageOutput did work) renderimage

So we think this error is based on problem related to base 64 transfer. Do you have any idea for this problem?

Thank you for your help. Manabe

wch commented 6 years ago

The problem likely is related to a locale issue, not base64 conversion. Can you supply a reproducible example app?

manabet commented 6 years ago

@wch Thank you for your reply.

Our environment:

We already installed IPA gothic fonts ttf file which is one of Japanese fonts.

Sample code

library(extrafont)
library(ggplot2)

ui <- fluidPage(
   # App title ----
   titlePanel("Hello Shiny!"),

   # Sidebar layout with input and output definitions ----
   sidebarLayout(
   # Sidebar panel for inputs ----
     sidebarPanel(
       # Input: Slider for the number of bins ----

       sliderInput(inputId = "bins",
                   label = "Number of bins:",
                   min = 1,
                   max = 50,
                   value = 30)
      ),
      # Main panel for displaying outputs ----

      mainPanel(
        # Output: Histogram ----
        plotOutput(outputId = "distPlot")
      )
    )
)

server <- function(input, output) {
       output$distPlot <- renderPlot({

           x <- faithful$waiting
           bins <- seq(min(x), max(x), length.out = input$bins + 1)

           hist(x, breaks = bins, col = "#75AADB", border = "white",
                xlab = "Waiting time to next eruption (in mins)",
                main = "Histogram of 待ち times")
       })
}

shinyApp(ui, server)

Regards