Tarzan
Tarzan

Reputation: 124

Scale ggplot output in Shiny app

I'm having trouble shrinking my plotOutput. All I want to do is slightly shrink the ggplot so there is a little padding in the box.

This is the image I have:

enter image description here

This is the image that I want:

enter image description here

The difference is subtle, but basically I just want to shrink the graph.

Upvotes: 0

Views: 685

Answers (1)

Gregor de Cillia
Gregor de Cillia

Reputation: 7655

The width argument in plotOutput can be used for that purpose. Then you can wrap the output in a div with central alignment.

library(ggplot2)
library(shiny)

gg <- ggplot(mtcars, aes(wt, mpg)) + geom_point() +
  theme(panel.background = element_rect(fill = 'grey'))

shinyApp(
  fluidPage(
    plotOutput('plot1'),
    div(
      plotOutput('plot2'),
      style = "padding-right: 10%; padding-left: 10%"
    )
  ),
  function(input, output, session){
    output$plot1 <- renderPlot(gg)
    output$plot2 <- renderPlot(gg)
  }
)

enter image description here

Upvotes: 1

Related Questions