5

I'm using ggplot2 to create graphics and embed them into a shinydashboard. The goal is to have everything as "transparent" as possible, which involves setting the background in theme as well as renderPlot to the same HEX code as the bacground of the dashboard:

library(shiny)
library(shinydashboard)
library(ggplot2)

ui <- dashboardPage(
  dashboardHeader(title = "Dashboard"),
  dashboardSidebar(),
  dashboardBody(
    column(4, plotOutput("plot")
    )
  )
)

server <- function(input, output) {
  output$plot <- renderPlot({
    ggplot(mpg, aes(displ, hwy, colour = class)) + 
      geom_point() +
      theme(plot.background = element_rect(fill = "#ECF0F5"))
  }, bg="transparent")
}

shinyApp(ui, server)

This produces the following output, which, however, has a very thin white space border around 3 sides of the graphics as below (I zoomed in and changed the white space to red for visibility. In the actual output it is white).

enter image description here

How can I eliminate this empty space?

Nate
  • 10,361
  • 3
  • 33
  • 40
Radek Janhuba
  • 193
  • 1
  • 6

0 Answers0