Control the height in fluidRow in R shiny

前端 未结 2 1676
情书的邮戳
情书的邮戳 2020-11-30 04:21

I am trying to build a layout for a shiny app. I have been looking at the application layout guide and did some google search but it seems the layout system in

相关标签:
2条回答
  • 2020-11-30 04:33

    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. 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.

    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) {
      }
    ))
    

    enter image description here

    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:

    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) {
      }
    ))
    

    enter image description here

    We passed a style tag to the head element here to stipulate our styling. There are a number of ways styling can be achieved see http://shiny.rstudio.com/articles/css.html

    0 讨论(0)
  • 2020-11-30 04:42

    For merging the top and bottom right, the key is to combine fluidRows and columns the right way. There is an official tutorial here (just replace boxes with columns). 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)
    

    0 讨论(0)
提交回复
热议问题