Configuring the size of ggplot chart

4,429 views
Skip to first unread message

Evan Zamir

unread,
Jul 16, 2013, 4:20:28 PM7/16/13
to shiny-...@googlegroups.com
I'm using ggplot along with ShinyGridster and am having trouble figuring out how to properly size my charts. For example, how can I set the output to 1200x800 pixels?
-evan

Evan Zamir

unread,
Jul 19, 2013, 1:57:01 PM7/19/13
to shiny-...@googlegroups.com
Does nobody know how to do this?

Evan Zamir

unread,
Jul 21, 2013, 2:54:55 PM7/21/13
to shiny-...@googlegroups.com
Well, it turned out to be quite easy. Just add some css to plotOutput:

plotOutput("plot",width="1000px",height="600px")



On Tuesday, July 16, 2013 1:20:28 PM UTC-7, Evan Zamir wrote:

Roy Francis

unread,
Jul 22, 2013, 9:13:00 AM7/22/13
to shiny-...@googlegroups.com
This worked for me. The png is generated by ggsave using predefined dimensions.
The figure is displayed in browser using the current session height and width. The figure resizes dynamically with browser
If the figure is saved, the original predefined dimensions are maintained.

#-----------------------------------------------------------------------------------
#Full working script shown
#ui.R
library(shiny)
library(reshape)
library(ggplot2)

shinyUI(pageWithSidebar(
  headerPanel("ggplot figure test"),
  sidebarPanel(),
  mainPanel(imageOutput("figure")
    )))

#server.R
library(datasets)

shinyServer(function(input, output,session) {
  
  
output$figure <- renderImage({
  width  <- session$clientData$output_figure_width
  height <- session$clientData$output_figure_height
  p2 <- ggplot(mtcars, aes(wt, mpg))+ geom_point()
  outfile <- "image.png"
  ggsave(outfile,p2,height=6, width=12,dpi=300)
  list(src = outfile, contentType = 'image/png', width = width, height = width/2, alt = "image")
  
},deleteFile = TRUE)
})
#-----------------------------------------------------------------------------------
Reply all
Reply to author
Forward
0 new messages