页面上的发光元素位置:在应用程序中每行显示一个框

时间:2018-11-26 12:49:46

标签: r shiny

enter image description here我设计的UI在“框”内具有“ infoBox”。 我想一次每个框,下一个框应显示在下一行。 但是我连续得到两个盒子。如何避免这种错误?

我的代码:

library(shiny)
library(shinydashboard)

ui <- shinyUI(dashboardPage(skin = "red",
dashboardHeader(title = "sample"),
dashboardSidebar(
sidebarMenu(
menuItem("a"))),
dashboardBody( 
tabPanel(h5("Labtest"),
box(h3("Hypertension"),
infoBox("Normal", "..." ,"Screened", icon = icon('users'), width = 4),
infoBox("Pre-Hypertension", "..." ,"Screened", icon = icon('male'), width = 
4),
infoBox("Hypertension" , "..." ,"Screened", icon = icon('female'), width = 
4)), 
box(h3("RBS"),
infoBox("Normal", "...", "Suspected", icon = icon('users'), width = 4),
infoBox("Pre-Diabetic", "...", "Suspected", icon = icon('male'), width = 4),
infoBox("Diabetic", "...", "Suspected", icon = icon('female'), width = 4)), 
box(h3("HB"),
infoBox("Normal", "...", "Suspected", icon = icon('users'), width = 4),
infoBox("Pre-Diabetic", "...", "Suspected", icon = icon('male'), width = 
4)), 
box(h3("Malaria"),
infoBox("Total Beneficiaries", "...", "referred to BBCI", icon = 
icon('users'), width = 4),
infoBox("suspected", "...", "referred to BBCI", icon = icon("male"), width = 
4)))
)))

server <- shinyServer(function(input,output){

})

shinyApp(ui, server)

2 个答案:

答案 0 :(得分:0)

您需要将每个box包装在fluidRow中。还要将width中的box设置为100%,否则它们将无法覆盖应用程序的整个宽度。

通过将小部件包装在fluidRow中,可以确保它们位于哪一行中。通过将它们包装在column中,可以设置小部件的水平空间。

您的应用程序:

library(shiny)
library(shinydashboard)

ui <- shinyUI(dashboardPage(skin = "red",
                            dashboardHeader(title = "sample"),
                            dashboardSidebar(
                              sidebarMenu(
                                menuItem("a"))),
                            dashboardBody( 
                              tabPanel(h5("Labtest"),
                                       fluidRow(style='margin: 0px;',
                                         box(width='100%',
                                           h3("Hypertension"),
                                             infoBox("Normal", "..." ,"Screened", icon = icon('users'), width = 4),
                                             infoBox("Pre-Hypertension", "..." ,"Screened", icon = icon('male'), width = 
                                                       4),
                                             infoBox("Hypertension" , "..." ,"Screened", icon = icon('female'), width = 
                                                       4))), 
                                       fluidRow(style='margin: 0px;',
                                         box(width='100%',
                                             h3("RBS"),
                                             infoBox("Normal", "...", "Suspected", icon = icon('users'), width = 4),
                                             infoBox("Pre-Diabetic", "...", "Suspected", icon = icon('male'), width = 4),
                                             infoBox("Diabetic", "...", "Suspected", icon = icon('female'), width = 4))), 
                                       fluidRow(style='margin: 0px;',
                                         box(width='100%',
                                             h3("HB"),
                                             infoBox("Normal", "...", "Suspected", icon = icon('users'), width = 4),
                                             infoBox("Pre-Diabetic", "...", "Suspected", icon = icon('male'), width = 
                                                     4))), 
                                       fluidRow(style='margin: 0px;',
                                         box(width='100%',
                                           h3("Malaria"),
                                           infoBox("Total Beneficiaries", "...", "referred to BBCI", icon = 
                                                     icon('users'), width = 4),
                                           infoBox("suspected", "...", "referred to BBCI", icon = icon("male"), width = 
                                                     4))))
                            )))

server <- shinyServer(function(input,output){

})

答案 1 :(得分:-1)

您必须将所需的信息框包装在列函数中。 像

column(width = 4,
    Box(width = NULL,
      infoBox(1),
      infoBox(2),

  )
)
column(width = 4,
     Box(width = NULL,
       infoBox(3)
  ))