将闪亮的地块缩放到窗口高度

时间:2014-11-06 14:35:30

标签: r shiny

我想将闪亮的绘图缩放到窗口的高度。当height = 100%更为可取时,此related SO question仅使用绝对高度规格(以像素为单位)。我在文档中注意absolutePanel可以通过其top, bottom, left, right参数实现此目的,但随后您丢失了侧面板,无论如何,绘图(在缩放到宽度时)似乎忽略了可用高度。 / p>

我猜测这与html怪癖有关,这意味着你需要通过javascript innerHeight变量获得高度。但我不清楚如何实现闪亮的解决方案以使ui.R能够利用它。感谢任何指针。

开发的基本应用模型:

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")
  )
)

1 个答案:

答案 0 :(得分:26)

使用CSS3。以视口单位http://caniuse.com/#feat=viewport-units声明您的高度。 您应该可以使用height中的plotOutput参数来声明它们,但是shiny::validateCssUnit无法识别它们,因此您可以在样式标题中声明它们:

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")
    )
  )
  )
)

这不会在闪亮的浏览器中运行,但应该可以在主浏览器中正常工作。

enter image description here