Michael Kozak Michael Kozak -4 years ago 112
R Question

objects allocation in Shiny

I am trying to make sort of a dashboard that contains 3 subjects. Therefore, I have made 3 boxes, but what i would like to achieve is that the 3 boxes in the main page, that will cover the entire width of the page, but they are very narrow.
For my understanding, the entire width of the page is 12 units, so I made this code:

library(shiny)
library(shinydashboard)

sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "main", icon = icon("dashboard")),
menuItem("Widgets", icon = icon("th"), tabName = "widgets")
)
)

body <- dashboardBody(
tabItems(
tabItem(tabName = "main",
tags$head(
tags$style(HTML("
h2,h4{
text-align: center;
}
"
))
),
h2("Title"),
h4("Dashboard"),
fluidRow(
column(4,
box(title="Advance Analysis Tools", hr(),
tags$ul( tags$li("Object"), tags$li("Object"), tags$li("Object"), tags$li("Object") ))),
column(4,
box(title="Quality",hr(),
tags$ul( tags$li("Object"),tags$li("Object")) )),
column(4,
box(title="Operation",hr(),
tags$ul( tags$li("Object"),tags$li("Object"),tags$li("Object"),tags$li("Object"), tags$li("Object"), tags$li("Object") )))
)
)

)
)

ui <- dashboardPage(
dashboardHeader(title = "Dashboard"),
sidebar,
body
)

server <- function(input, output) {

}

shinyApp(ui, server)


but the 3 boxes are not spread correctly.

Please advise.

Thanks in advance,

Michael

Answer Source

the box() function also has a width argument just like you used it for the column() function. As you probably already know 12 is the maximum value for that parameter. Note that the width of the box is in relation to the column width. A column with a width parameter of 4 including a box with a width parameter of 12 results in a column that is fully filled with the box and has a width of 4.

So you can use something like.

 column(4, 
   box(title="Operation",hr(), width = 12, ...

If you want to get rid of the blank spaces in between use sthg like: offset = 0, style='padding:0px;' see here: shiny fluidrow column white space

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download