2014-11-06 57 views
18

我想缩放到窗口高度的闪亮情节。这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") 
) 
) 

回答

22

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

在闪亮的浏览器,但这个不会工作应在正常工作主浏览器。

enter image description here

+0

点上,感谢约翰 – geotheory 2014-11-06 19:00:27

+0

我有一个类似的问题,但是自从我使用'navbarPage'我似乎无法得到CSS工作http://stackoverflow.com/questions/30179621/how-can-i-display-my-plot-without-toolbars-in-shiny – 2015-05-12 16:44:48

+0

我正在尝试这种方法,但在绘图中增加了一个'height = 400px',这似乎覆盖了我在'tag'功能。任何线索? – TheComeOnMan 2015-08-08 10:18:30