I can't figure out how to vertically align text within a "box" using R shiny dashboard. I know you can't vertically align text inline using e.g., span. Padding hasn't worked for me (though I might be doing it wrong).
Most promisingly, I saw this suggestion to create a tag style with flex display--but it only works to center the text horizontally, not vertically! Perhaps I'm adding the style info to the wrong place. Here's some "app.R" code that shows off the issue:
# ------------------------------------------------------------------------------
# SET-UP
library(shiny) # shiny application
library(shinydashboard) # shiny dashboard toolkit
rm(list = ls()) # remove variables from working environment
shinyOptions(cache = cachem::cache_disk("./app_cache/cache/"))
boxHeight = "30em" # Box height
# ------------------------------------------------------------------------------
# CREATE DASHBOARD
# Header content
header <- dashboardHeader(
title = span("Play Dashboard",
style = "color: white; font-size: 28px"),
disable = FALSE,
titleWidth = 550
)
# Sidebar content
sidebar <- dashboardSidebar(
width = 260,
collapsed = TRUE,
sidebarMenu(
menuItem("Dashboard Tab 1", tabName = "tab1", icon = icon("tachometer-alt"))
)
)
# Body content
body <- dashboardBody(
# Here, I try to implement the earlier Stack Overflow suggestion
tags$style(HTML('
#textbox {
display: flex;
align-items: center;
justify-content: center;
align-content: center;
}
')),
tabItems(
# 1ST TAB: KEY ECONOMIC INDICATORS
tabItem(tabName = "tab1",
fluidRow(
box(height = boxHeight,
id = "textbox",
"This isn't vertically centered."),
box(
height = boxHeight,
id = "textbox",
span("This isn't vertically centered, either.", id="textbox"),
),
box(height = boxHeight,
span("Nor is this!", id="textbox")),
box(height = boxHeight,
"But they're all horizontally centered, unlike this ...")
)
)
)
)
server <- function(input,output){
}
#Dashboard page
dashboard <- dashboardPage(header, sidebar, body, tags$head(tags$style(HTML('* {font-family: "Lucida Sans"}!important;'))))
shinyApp(dashboard, server)
Any help would be appreciated!


