简体   繁体   English

R闪亮-1行中有多个valueBox

[英]R Shiny - Multiple valueBoxes in 1 row

I am fairly new to R Shiny and I would like to create 1 row with 8 valueBoxes. 我对R Shiny相当陌生,我想创建一个包含8个valueBoxes的行。 I used the code below but it is not showing all boxes on the same row. 我使用下面的代码,但未在同一行上显示所有框。 I tried setting the width to 1.5 (given the Bootstrap width of 12, divided over 8 boxes), but it doesn't seem to accept decimal values. 我尝试将宽度设置为1.5(考虑到Bootstrap的宽度为12,分为8个框),但是它似乎不接受十进制值。 Any ideas? 有任何想法吗?

  fluidRow( 
    valueBoxOutput("box1"),
    valueBoxOutput("box2"),
    valueBoxOutput("box3"),
    valueBoxOutput("box4"),
    valueBoxOutput("box5"),
    valueBoxOutput("box6"),
    valueBoxOutput("box7"),
    valueBoxOutput("box8")
  )

You can make use of shiny's grid layout by placing each object in a separate column. 您可以通过将每个对象放在单独的列中来使用闪亮的网格布局。 Try: 尝试:

 fluidRow( 
    column(1, valueBoxOutput("box1")),
    column(1, valueBoxOutput("box2")),
    column(1, valueBoxOutput("box3")),
    column(1, valueBoxOutput("box4")),
    column(1, valueBoxOutput("box5")),
    column(1, valueBoxOutput("box6")),
    column(1, valueBoxOutput("box7")),
    column(1, valueBoxOutput("box8"))
  )

You can use splitLayout : 您可以使用splitLayout

library(shinydashboard)

shinyApp(
  ui = fluidPage(
    splitLayout(
      valueBoxOutput("box1"),
      valueBoxOutput("box2"),
      valueBoxOutput("box3"),
      valueBoxOutput("box4"),
      valueBoxOutput("box5"),
      valueBoxOutput("box6"),
      valueBoxOutput("box7"),
      valueBoxOutput("box8")
    )
  ),
  server = function(input, output){
    output$box1 <- renderInfoBox({
      infoBox(
        "box1",
        "A",
        icon = icon("credit-card")
      )
    })
    output$box2 <- renderInfoBox({
      infoBox(
        "box2",
        "B",
        icon = icon("credit-card")
      )
    })
    output$box3 <- renderInfoBox({
      infoBox(
        "box3",
        "C",
        icon = icon("credit-card")
      )
    })
    output$box4 <- renderInfoBox({
      infoBox(
        "box4",
        "D",
        icon = icon("credit-card")
      )
    })
    output$box5 <- renderInfoBox({
      infoBox(
        "box5",
        "E",
        icon = icon("credit-card")
      )
    })
    output$box6 <- renderInfoBox({
      infoBox(
        "box6",
        "F",
        icon = icon("credit-card")
      )
    })
    output$box7 <- renderInfoBox({
      infoBox(
        "box7",
        "G",
        icon = icon("credit-card")
      )
    })
    output$box8 <- renderInfoBox({
      infoBox(
        "box8",
        "H",
        icon = icon("credit-card")
      )
    })
  }
)

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

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