如何在 R shiny 中对齐值框右侧的文本?

How to align the text on the right side of the value box in R shiny?

我正在尝试在值框中写入文本。我想在同一行中将左侧的一些文本和右侧的一些文本对齐。 我试过这段代码:

library(shiny)
library(shinydashboard)
library(flexdashboard)


ui <- dashboardPage(skin = 'purple',
                    dashboardHeader(),
                    dashboardSidebar(),
                    
                    dashboardBody(skin = 'purple',
                                  
                                  fluidRow(
                                    shinydashboard::valueBoxOutput("header", width = 12)
                                  )))


server <- function(input, output) {
  
  output$header <- shinydashboard::renderValueBox({
    shinydashboard::valueBox(tags$p("Hello World!", style ="color : black"), "Hi!")
  })
  
}

shinyApp(ui, server)

使用上面的代码,我得到了这个:

但是我想这样显示:

Hello 在值框的左侧,World! 在值框的右侧。 如果这在值框中是可能的,我该怎么做?

如果您想对元素使用不同的样式,最好的办法是将它们分成不同的标签。

在这种情况下,我建议使用 span,因为它是一个内联标记。使用 html 和 css 对齐对象的方式有很多种。我相信最简单的方法就是将 float:right 添加到第二个 span 标签。

output$header <- shinydashboard::renderValueBox({
    shinydashboard::valueBox(tags$p(tags$span("Hello"),tags$span("World!", style = "float:right"), style ="color : black"), "Hi!")
  })