将闪亮的地块缩放到窗口高度 [英] Scaling shiny plots to window height

查看:8
本文介绍了将闪亮的地块缩放到窗口高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将闪亮的绘图缩放到窗口的高度。当height = 100%更可取时,related SO question仅使用以像素为单位的绝对高度规格。我在文档中注意到,absolutePanel可以通过其top, bottom, left, right参数实现这一点,但是这样您就会丢失侧面板,而且无论如何绘图(缩放到宽度时)似乎会忽略可用高度。

我猜这与html怪癖有关,这意味着您需要使用javascriptinnerHeight变量获取高度。但我不清楚如何在SHINY中实现解决方案来让ui.R利用这一点。感谢您的任何指点。

开发APP的基本模型:

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

推荐答案

使用css3。以视口单位http://caniuse.com/#feat=viewport-units声明您的高度。 您应该能够使用plotOutput中的height参数声明它们,但是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")
    )
  )
  )
)

这在闪亮的浏览器中不起作用,但应该能在主浏览器中正常工作。

这篇关于将闪亮的地块缩放到窗口高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆