【发布时间】:2017-12-07 19:42:53
【问题描述】:
plotOutput 或 renderPlot 似乎在情节周围添加了一堆额外的空白。我在绘图和布局列中添加了背景颜色来说明这一点。从本质上讲,我想完全摆脱这个空白,只留下蓝色区域,然后它应该与列的左侧对齐。
我知道这可以使用 width 参数进行调整,但是将其设置为 100% 或 auto 似乎无法正常工作。
谢谢!
library(shiny)
library(ggplot2)
# Create sample data
animals <- as.data.frame(
table(Species =
c(rep("Moose", sample(1:100, 1)),
rep("Frog", sample(1:100, 1)),
rep("Dragonfly", sample(1:100, 1))
)))
server <- function(input, output) {
output$pieChart <- renderPlot({
# Create pie chart
ggplot(animals, aes(x = "", y = Freq, fill = Species)) +
geom_bar(width = 1, stat = "identity") +
coord_polar("y", start=0) +
theme(plot.background = element_rect(fill = "lightblue"))
})
}
ui <- fluidPage(
fluidRow(
column(4,
style = "background-color:lightgreen",
align = "left",
HTML("filler<br>"),
plotOutput("pieChart")
)
)
)
shinyApp(ui = ui, server = server)
【问题讨论】:
-
嗨,几年后我遇到了几乎同样的问题 - 我想知道你是否设法找到了更优雅的解决方案?
-
已经有一段时间了,但我相信我选择了下面 Brian 的解决方案