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

showtext, ggplot2 and shinyapps #6

Closed
Spatial-R opened this issue Feb 29, 2016 · 5 comments
Closed

showtext, ggplot2 and shinyapps #6

Spatial-R opened this issue Feb 29, 2016 · 5 comments

Comments

@Spatial-R
Copy link

Thanks for you showtext package. Recently, i want to use the WenQuanYi Micro Hei to show Chinese characters in my figures. After loading the font using the codes font.add("wqy", regular = "wqy-microhei.ttc") , the Chinese characters will show well in the figures created by the basic figure system but not for that created by the ggpplot2 package( set using the codes: theme_bw(base_family="wqy")) after publishing to the shinyapps.
How could i solve the problem? Thanks

@yixuan
Copy link
Owner

yixuan commented Feb 29, 2016

Hi Bing,
Did you call the showtext.auto() or showtext.begin() function? Could you show me a piece of code?
And actually showtext already contains a copy of the Micro Hei font, via the family name wqy-microhei, so you can directly use that one.

@Spatial-R
Copy link
Author

library(shiny);library(ggplot2);library(showtext)

ui <- shinyUI(fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30) ),
mainPanel(plotOutput("distPlot"))
)))

server <- shinyServer(function(input, output) {
output$distPlot <- renderPlot({
showtext.begin()
x <- faithful[, 2]
ggplot(data=dat,aes(x=x,y=x))+geom_point()+
theme_bw(base_size = 12,base_family ="wqy-microhei")
showtext.end()
})
})
shinyApp(ui = ui, server = server)

@yixuan
Copy link
Owner

yixuan commented Mar 2, 2016

It works on my machine. Did you forget to print() the ggplot2 graph?

library(shiny);library(ggplot2);library(showtext)

ui <- shinyUI(fluidPage(
    titlePanel("Old Faithful Geyser Data"),
    sidebarLayout(
        sidebarPanel(
            sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30) ),
        mainPanel(plotOutput("distPlot"))
    )))

server <- shinyServer(function(input, output) {

    output$distPlot <- renderPlot({
        showtext.begin()
        g = ggplot(data = faithful, aes(x = eruptions)) +
            geom_histogram(bins = input$bins) +
            ggtitle("直方图") +
            theme_bw(base_size = 30, base_family = "wqy-microhei")
        print(g)
        showtext.end()
    })
})

shinyApp(ui = ui, server = server)

showtext_shiny

@Spatial-R
Copy link
Author

Thanks! I had solved the problem using the way!

@yixuan
Copy link
Owner

yixuan commented Mar 5, 2016

Great! Then I'll close this issue.

@yixuan yixuan closed this as completed Mar 5, 2016
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