【发布时间】:2021-12-08 15:35:56
【问题描述】:
我不知道如何使用 R 闪亮的仪表板在“框”内垂直对齐文本。我知道you can't vertically align text inline using e.g., span。填充对我不起作用(尽管我可能做错了)。
最有希望的是,我看到this 建议使用 flex 显示创建标签样式——但它只能使文本水平居中,而不是垂直居中!也许我将样式信息添加到错误的地方。下面是一些显示问题的“app.R”代码:
# ------------------------------------------------------------------------------
# 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)
任何帮助将不胜感激!
【问题讨论】:
标签: r shiny shinydashboard