0

I'm building a R Shiny application focused around selecting data and creating a variety of plots using the R base plotting procedures, and place in plotOutput elements in Shiny. Since the application is rendered in a web page, the user can change the size of the browser window to modify the aspect ratio of the plot to what is most pleasing. To capture a plot for, say, a report or presentation, the user can always copy/paste the image from the browser window, but the resolution is only that which is provided by the user's monitor. The plot can also be sent to a png (jpg, etc.) file but the aspect ratio of the plot needs to be specified.

What I'm looking for is a way to 'read' the aspect ratio (or more likely the height and width) of the screen plot and send the resulting height/width to the png(...) function at any arbitrary resolution. The logic would go like this:

  • Select data
  • Render plot in a Shiny plotOutput window
  • Resize browser
  • Read the plot window dimensions
  • Calculate the height/width of the png rendering at the desired
    resolution
  • Call png(file,width=Width,height=Height,res=600)

The package shinybrowser can read the initial browser dimensions (as suggested in Get the size of the window in Shiny)

library(shiny)

ui <- fluidPage(
    shinybrowser::detect(),
    "Window size:",
    textOutput("size")
)

server <- function(input, output, session) {
    output$size <- renderText({
        paste(
            shinybrowser::get_width(),
            "x",
            shinybrowser::get_height()
        )
    })
}

shinyApp(ui, server)

however there doesn't appear to be a way to find the browser dimensions, never mind the plot object dimensions, after the browser is resized, though the information above is 2 years old. I'd appreciate any help in seeing if this is possible.

Thanks!

Dr Dave
  • 453
  • 1
  • 4
  • 11

0 Answers0