简体   繁体   English

控制流体中的高度R在R中闪亮

[英]Control the height in fluidRow in R shiny

I am trying to build a layout for a shiny app. 我正在尝试为shiny应用程序构建布局。 I have been looking at the application layout guide and did some google search but it seems the layout system in shiny has its limits. 我一直在看应用程序布局指南 ,并进行了一些谷歌搜索,但似乎闪亮的布局系统有其局限性。

You can create something like this: 你可以创建这样的东西:

fluidPage(
 fluidRow(
  column(6,"Topleft"),
  column(6,"Topright")),
 fluidRow(
  column(6,"Bottomleft"),
  column(6,"Bottomright"))
)

This gives you 4 same sized objects. 这为您提供了4个相同大小的对象。

Is it possible now to give the 2 Top-Objects a different height as the Bottom-Objects ? 现在可以将2个Top-Objects作为Bottom-Objects Top-Objects提供不同的高度吗?

And is it possible to merge the Topright-Object and the Bottomright-Object ? 并且可以合并Topright-ObjectBottomright-Object吗?

The height of the rows is responsive and is determined by the height of the elements of the columns. 行的高度是响应的,并且由列的元素的高度确定。 As an example we use two elements in the first row with heights 200 and 100 pixels respectively. 作为示例,我们在第一行中使用两个元素,分别具有高度200和100像素。 The row takes the maximum height of its elements. 该行采用其元素的最大高度。 The second row has elements with heights 100 and 150 pixels respectively and again takes the height of the largest element. 第二行具有分别具有高度100和150像素的元素,并且再次获取最大元素的高度。

library(shiny)
runApp(list(
  ui = fluidPage(
    fluidRow(
      column(6,div(style = "height:200px;background-color: yellow;", "Topleft")),
      column(6,div(style = "height:100px;background-color: blue;", "Topright"))),
    fluidRow(
      column(6,div(style = "height:100px;background-color: green;", "Bottomleft")),
      column(6,div(style = "height:150px;background-color: red;", "Bottomright")))
  ),
  server = function(input, output) {
  }
))

在此输入图像描述

For greater control the idea with libraries like bootstrap is that you style your elements with CSS so for example we can add a class to each row and set its height and other attributes as we please: 为了更好地控制像bootstrap这样的库的想法是用CSS设置元素的样式,例如我们可以为每一行添加一个类,并根据需要设置它的高度和其他属性:

library(shiny)
runApp(list(
  ui = fluidPage(
    fluidRow(class = "myRow1", 
      column(6,div(style = "height:200px;background-color: yellow;", "Topleft")),
      column(6,div(style = "height:100px;background-color: blue;", "Topright"))),
    fluidRow(class = "myRow2",
      column(6,div(style = "height:100px;background-color: green;", "Bottomleft")),
      column(6,div(style = "height:150px;background-color: red;", "Bottomright")))
    , tags$head(tags$style("
      .myRow1{height:250px;}
      .myRow2{height:350px;background-color: pink;}"
      )
    )
  ),
  server = function(input, output) {
  }
))

在此输入图像描述

We passed a style tag to the head element here to stipulate our styling. 我们在这里将样式标签传递给head元素以规定我们的样式。 There are a number of ways styling can be achieved see http://shiny.rstudio.com/articles/css.html http://shiny.rstudio.com/articles/css.html可以通过多种方式实现样式化

For merging the top and bottom right, the key is to combine fluidRows and columns the right way. 对于合并右上角和右下角,关键是以正确的方式组合fluidRowscolumns There is an official tutorial here (just replace boxes with columns ). 有一个官方的教程在这里 (只需更换boxescolumns )。 Example also here 这里也有例子

If you wish to combine top right and bottom right, you could use one single row which contains two columns. 如果您希望将右上角和右下角组合在一起,则可以使用包含两列的单行。 The first (left) column again contain two rows, the right column one big row for the combination: 第一(左)列再次包含两行,右列为组合的一大行:

ui <- shinyUI(fluidPage(
  fluidRow(
    column(width=6,
           fluidRow("Topleft", style = "height:200px; background-color: yellow;"),
           fluidRow("Bottomleft", style = "height:200px; background-color: green;")),
    column(width = 6,
           fluidRow("Topright and Bottomright", style = "height:400px; background-color: grey;")))
))
server <- function(input, output) {}
shinyApp(ui, server)

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM