css - 在R Shiny中的fluidRow中设置不等列长度文本的格式

标签 css r layout shiny shinydashboard

我目前正在构建一个 Shiny 的应用程序,并且想要显示一些文本 block 。文本 block 的长度不同,我想为每个 block 着色,并且 block 之间也有一些间隙。

但是,由于 block 具有不同的文本长度,我只能将 block 着色到有文本的位置,而不是空白区域。然而,这会导致颜色有点难看。

而且,列之间的最小间隙显然是 1,从视觉 Angular 来看,这个间隙太大了。

CurrentFormatting

我想要的是将 B 列和 C 列的颜色减小到 A 列的长度。 我还想减少列之间的间隙,并将其设置为偏移量 1,但无法将其偏移到 < 1 的分数。

这是生成上图的代码:

    ui <- fluidPage(
  mainPanel(
    tabsetPanel(
      tabPanel("Data Visualization",
               fluidRow(
                 column(3,h3("Title A",align = "center"),style = "background-color: red;"),
                 column(3,h3("Title B",align = "center"),style = "background-color: yellow;",offset = 1),
                 column(3,h3("Title C",align = "center"),style = "background-color: green;",offset = 1)
               ),
               fluidRow(
                 column(3, h4(tags$li("Text A")),style = "background-color: red;"),
                 column(3,tags$li(h4("Text B")),style = "background-color: yellow;",offset = 1),
                 column(3,tags$li(h4("Text C")),style = "background-color: green;",offset = 1)                       
               ),
               fluidRow(
                 column(3, h4(tags$li("More Text A")),style = "background-color: red;"),
                 column(3,"",style = "background-color: yellow;", offset = 1),
                 column(3,"",style = "background-color: green;", offset = 1)                       
               ),    
               fluidRow(
                 column(3, h4(tags$li("More and More Text A")),style = "background-color: red;"),
                 column(3,"",style = "background-color: yellow;", offset = 1),
                 column(3,"",style = "background-color: green;", offset = 1)                       
               )
))))

server <- function(input,output) {}

shinyApp(ui = ui, server = server)

请告诉我如何在没有任何硬编码像素宽度的情况下设置样式(因为这可能会影响不同屏幕尺寸的观看体验)以使颜色等于最大长度列。

如果有另一种方法可以使此类文本框 Shiny ,那么了解一下也会有所帮助。

非常感谢!

最佳答案

我认为使用shinydashboard::box()将是一种更简单的方法:

library(shiny)
library(shinydashboard)

body <- dashboardBody(
# change this to set space between boxes
  tags$head(tags$style(
    HTML('.row div {padding: 0% 1% 0% 1% !important;}'))), 
  
  fluidRow(
    box(
      title = "Title A", width = 4, background = "red",
      "Some text that is contained within a red box"
    ),
    box(
      title = "Title B", width = 4, background = "yellow",
      "Some text that is contained within a yellow box and also a bit longer
      than the other boxes."
    ),
    box(
      title = "Title C",width = 4, background = "green",
      "Some text that is contained within a green box"
    )
  ), 
  
  fluidRow(
    box(
      width = 4, background = "red", 
      "And simply don't specify a title to create some more text about topic A."
    )
  )
)

ui <- dashboardPage(
  dashboardHeader(title = "Example of Dashboard"),
  dashboardSidebar(),
  body
)

shinyApp(ui = ui, server = function(input, output) { })

这给了你 enter image description here

关于css - 在R Shiny中的fluidRow中设置不等列长度文本的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70913478/

相关文章:

css - 完全居中图像?

jquery - FlowType 模板不调整元素大小

html - HTML anchor 在距顶部 300px 的绝对 DIV 中有问题..?

r - 如何使用 R 根据另一个数据帧列的值改变数据帧的某些值

r - 在data.table中按组cbind列表的有效方法

android - 如何为所有 Activity 设置固定方向

javascript - div 中文本的 JQuery 选择器

python - 有没有更有效的方法来枚举 python 或 R 中离散随机变量的每个可能结果的概率?

Java Swing 设置 JPanel 大小

android - eclipse 图形布局不显示任何内容