Either plotOutput
or renderPlot
seems to add a bunch of extra white space around a plot. I've added background colours to the plot and the layout column to illustrate this. Essentially, I would like to be completely rid of this white space, leaving only the area coloured in blue, which should then align itself to the left of the column.
I know that this can be adjusted using the width
argument, but having it a either 100%
or auto
doesn't seem to work properly.
Thanks!
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)
See Question&Answers more detail:os