0

I have a shiny app with a ggplot. If I upload it to shinyapps.io or if I make the ggplot outside a shinyapp in Rstudio it shows fonts correctly, but when I display it in the Rstudio browser or system browser doesn't show the correct fonts, just the default one in the ggplot.

   ui <- fluidPage(
        titlePanel("Hello Shiny!"),
        sidebarLayout(
            sidebarPanel(),
            mainPanel(
                plotOutput(outputId = "distPlot")
            )
        )
    )
    server <- function(input, output) {
        output$distPlot <- renderPlot({
            myFont1 <- "Montserrat"
            myFont2 <- "Roboto"
            myFont3 <- "CourierNew"

            library(ggplot2)
            a <- ggplot(mtcars, aes(x = wt, y = mpg)) + 
                geom_point() +
                ggtitle("Montserrat") +
                theme(text = element_text(size = 16, family = myFont1)) +
                annotate("text", 4, 30, label = 'Roboto',
                         family = myFont2, size = 10) +
                annotate("text", 1, 11, label = 'Courier New', hjust = 0,
                         family = myFont3, size = 10) 
            a
        })
    }

shinyApp(ui=ui, server=server)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.