我正在尝试将一个漂亮的字体应用于在Shiny应用程序中呈现的ggplot .
使用family =“[fontname]”在RStudio中设置所需的字体(在同一服务器上)可以正常工作 . 这里要求使用“serif”字体系列:
但是,当ggplot嵌入到Shiny renderPlot({})函数中时,字体系列不会更改默认值 . 这里要求使用相同的“serif”字体系列:
字体大小和字体(粗体,斜体)的更改按预期工作 . 我已经在RStudio和闪亮的应用程序中使用fonts()和pdfFonts()检查了已安装的字体名称,然后尝试了列出的以及“serif”,“sans”和“mono”,但都无济于事 . 我也尝试过loadfonts() .
一个最小的例子:
server.R
require(ggplot2)
require(ggthemes)
require(extrafont)
shinyServer(function(input, output) {
df
output$the_plot
p
xlab("Alpha") +
ylab("Beta") +
geom_point() +
theme(text=element_text(family="serif", size=16))
print(p)
})
})
ui.R
library(shiny)
shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
h6("Font test")
),
mainPanel(
plotOutput("the_plot")
)
)
))
Edit: 有a similar unanswered question但是寻求pdf而不是png输出 . 现在也尝试过R基本图形而不是ggplot,结果相同 .