下面的代码显示2
ggplot2
图中的情节
shinydashboard
. 情节背景应该总是
透明的
甚至
调整大小后
.
启动应用程序时,绘图正确显示,但一旦调整屏幕大小或关闭siderbar,背景就会再次变为白色。
这是为什么,我怎样才能防止呢?
关闭边栏时,背景变为白色,重新打开边栏后,绘图再次切换为透明。
但是,当调整窗口大小时,无论发生什么,它都不会变回透明。除了可能调整到默认的窗口尺寸。我没试过;)
这在rstudio和浏览器(chrome和firefox)中发生。
我知道一个选项是将ggplots的背景色更改为shinyapp的背景色。但我希望这不是唯一的。
library(shiny)
library(shinydashboard)
library(ggplot2)
df <- data.frame(
id = rep(1:5, each=5),
a = runif(25, 2, 50)
)
ui = {dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
splitLayout(cellWidths = c("50%", "50%"),
plotOutput("boxplot"),
plotOutput("vioplot")
)
)
)}
server <- function(input, output) {
output$boxplot <- renderPlot({
ggplot(df, aes(x=id, y=a, group=id)) +
geom_boxplot(aes(fill=id)) +
facet_grid(~id, margins = T) +
theme(rect=element_blank(),
panel.grid = element_blank(),
panel.background= element_blank(),
plot.background = element_blank()
)
}, bg="transparent")
output$vioplot <- renderPlot({
ggplot(df, aes(x=id, y=a, group=id)) +
geom_violin(aes(fill=factor(id))) +
facet_grid(~id, margins = T) +
theme(rect=element_blank(),
panel.grid = element_blank(),
panel.background= element_blank(),
plot.background = element_blank()
)
}, bg="transparent")
}
shinyApp(ui, server)