【问题标题】:Scaling shiny plots to window height将闪亮的图缩放到窗口高度
【发布时间】:2015-01-03 02:40:17
【问题描述】:

我想将闪亮的绘图缩放到窗口的高度。这个related SO question 仅使用以像素为单位的绝对高度规范,而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))
    })
  }
)

server.R

library(shiny)
pageWithSidebar(
  headerPanel("window height check"),
  sidebarPanel(),
  mainPanel(
    plotOutput("myplot")
  )
)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

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

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

    【讨论】:

    • 我遇到了类似的问题,但由于我使用的是navbarPage,我似乎无法让 CSS 工作stackoverflow.com/questions/30179621/…
    • 我正在尝试这种方法,但图中添加了一个height = 400px,它似乎覆盖了我在tag 函数中指定的高度。有什么线索吗?
    • 只是为了拯救不太了解 CSS 的人:如果您有多个选项卡,则使用 CSS 类 shiny-plot-output 而不是 ID 即像 tags$head(tags$style(".shiny-plot-output{height:100vh !important;}")) 这样的设置适用于所有标签
    猜你喜欢
    • 2017-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    • 1970-01-01
    • 2017-11-03
    • 2015-12-06
    • 1970-01-01
    相关资源
    最近更新 更多