I want to scale a shiny plot to the height of the window. This related SO question only uses absolute height specifications in pixels, when a height = 100%
would be preferable. I note in the documentation that absolutePanel
can achieve this with its top, bottom, left, right
arguments, but then you lose the side panel, and in any case the plot (while scaling to width) seems to ignore available height.
I'm guessing this relates to the html quirk that means you need to get the height with javascript innerHeight
variable. But I'm unclear how to implement a solution in shiny to get ui.R
to utilise this. Grateful for any pointers.
A basic app model for development:
ui.R
library(shiny) shinyServer( function(input, output) { output$myplot <- renderPlot({ hist(rnorm(1000)) }) } )
server.R
library(shiny) pageWithSidebar( headerPanel("window height check"), sidebarPanel(), mainPanel( plotOutput("myplot") ) )
Use CSS3. Declare your height in viewport units http://caniuse.com/#feat=viewport-units . You should be able to declare them using the height
argument in plotOutput
however shiny::validateCssUnit
doesnt recognise them so you can instead declare them in a style header:
library(shiny) runApp( list(server= function(input, output) { output$myplot <- renderPlot({ hist(rnorm(1000)) }) } , ui = pageWithSidebar( headerPanel("window height check"), sidebarPanel( tags$head(tags$style("#myplot{height:100vh !important;}")) ), mainPanel( plotOutput("myplot") ) ) ) )
This wont work in the shiny browser but should work correctly in a main browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With