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, they don't show the correct fonts, just the default one.
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)
Also asked in: https://community.rstudio.com/t/shinyapp-in-rstudio-in-ubuntu-not-showing-correct-fonts-in-ggplot/39515