Search code examples
rr-markdownflexdashboard

How to center values in boxvalues for shiny/flexdashboard?


I have these box values here at the top of my dashboard. I want to center align the title and the value.

enter image description here


Solution

  • in order to reproduce your example, I used a shinydashboard skeleton, I put the infobox inside a column() that was inside a fluidRow. The trick was adding width = 3,align="center" in the column.

    library(shiny)
    library(shinydashboard)
    
    ui <- dashboardPage(
      dashboardHeader(),
      dashboardSidebar(),
      dashboardBody(fluidRow(
        # A static infoBox
       column( infoBox("New Orders", 10 * 2, icon = icon("credit-card")), width = 3,align="center"),
    
        ),)
    )
    
    server <- function(input, output) { }
    
    shinyApp(ui, server)
    
    • Which centered my infobox

    enter image description here

    To render this in a Rmd file just use this

    ---
    title: "Untitled"
    author: "Daniel"
    date: "5/6/2021"
    output: html_document
    runtime: shiny
    ---
    
    ```{r}
    library(shiny)
    library(shinydashboard)
    
    ui <- dashboardPage(
      dashboardHeader(),
      dashboardSidebar(),
      dashboardBody(fluidRow(
        # A static infoBox
       column( infoBox("New Orders", 10 * 2, icon =     icon("credit-card")), width = 3,align="center"),
    
        ),)
    )
    
    server <- function(input, output) { }
    
    shinyApp(ui, server)
    ```
    

    You have to zoom into the Rmarkdown file shiny window for the responsive effect.

    enter image description here