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

geo*_*ory 24 r shiny

我想将闪亮的绘图缩放到窗口的高度.这个相关的SO问题仅使用绝对高度规格(以像素为单位),当a height = 100%更为可取时.我在文档中注意到absolutePanel可以用它的top, bottom, left, right参数实现这一点,但是你丢失了侧面板,并且无论如何情节(缩放到宽度)似乎忽略了可用的高度.

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

开发的基本应用程序模型:

ui.R

library(shiny)
shinyServer(
  function(input, output) {
    output$myplot <- renderPlot({
      hist(rnorm(1000))
    })
  }
)
Run Code Online (Sandbox Code Playgroud)

server.R

library(shiny)
pageWithSidebar(
  headerPanel("window height check"),
  sidebarPanel(),
  mainPanel(
    plotOutput("myplot")
  )
)
Run Code Online (Sandbox Code Playgroud)

jdh*_*son 28

使用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")
    )
  )
  )
)
Run Code Online (Sandbox Code Playgroud)

这不会在闪亮的浏览器中工作,但应该在主浏览器中正常工作.

在此输入图像描述

  • 只是为了拯救一个不太了解CSS的人:如果你有多个标签,那么使用CSS类`shiny-plot-output`而不是ID,比如`tags $ head(tags $ style(".shiny-plot) -output {height:100vh!important;}"))`这个设置适用于所有标签 (7认同)