html - 在仪表板标题中间对齐可变长度的文本

标签 html css shiny

我使用shiny-dashboard包,标题需要有标题、文本和 Logo 。

标题应位于左侧,文本应位于标题的中间/中心, Logo 应位于右侧。仪表板侧边栏还有两个过滤器(选择输入)。中间的文本显示用户选择,因此文本的长度根据不同的选择而不同。我没有 css 背景,也不知道如何将可变长度文本放置在标题的中心。另一个问题是,当我最小化屏幕时,文本和 Logo 会堆叠在一起,并且不会保持在一行中,如下所示:

enter image description here

为了简化代码,我只使用了一个简单的文本,并且没有在此处显示我的服务器代码,但“长度可变的长文本取决于用户选择”基本上是一个 uiOutput 并且将是根据选择而改变。

shinyApp(
  ui = dashboardPage(
dashboardHeader( 

  title = HTML(paste0("Dashboard example")) , titleWidth = 455,
  tags$li(class="dropdown",
          tags$table(style="80%;align:center;border-collapse:seperate;border-spacing:20px;",
                     tags$tr(
                       tags$td(h3("long text with variable length dependant on user selections")),
                       tags$td(
                         a(href='link',
                           img(src = 'http://www.clipartbest.com/cliparts/nTX/8nj/nTX8njyEc.jpeg',
                               title= "image title", height = "50px"),
                           style = "display:block;position:absolute,width:50px; padding-top:10px; padding-bottom:10px;padding-right:10px;"),
                         class="dropdown"))))),
dashboardSidebar(),
dashboardBody(tags$head(
  tags$style(HTML("
                  .my_class {
                  font-weight: bold;
                  color:white;
                  }"))
))),
  server = function(input, output) { }
  )

expected result

最小化屏幕会破坏标题,如下所示

使用下面提供的代码,我明白了。 enter image description here

最佳答案

尝试这样的事情:

library(shiny)
library(shinydashboard)

shinyApp(
  ui = dashboardPage(
    dashboardHeader( 
      title = "Dashboard example",
      titleWidth = 455,
      tags$li(
        class = "dropdown",
        fluidRow(
          column(
            width = 4, 
            offset = 4, 
            align = "center",
            span("long text with variable length dependant on user selections")
          ),
          column(
            width = 4,
            align = "right",
            img(src = 'http://www.clipartbest.com/cliparts/nTX/8nj/nTX8njyEc.jpeg')
          )
        )
      )
    ),
    dashboardSidebar(width = 455),
    dashboardBody(
      tags$style(
        ".main-header .navbar-custom-menu {
          width: calc(100% - 50px);
        }

        .main-header .navbar-nav,
        .main-header .dropdown {
          width: 100%;
        }

        .main-header img {
          height: 50px
        }"
      )
    )
  ),
  server = function(input, output) {}
)

关于html - 在仪表板标题中间对齐可变长度的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54434402/

相关文章:

JavaScript-不显示文本 Accordion 中的标题

css - 有没有办法从嵌入的 PDF 对象中删除 Adob​​e 边框?

css - 如果超过 6 个字母,则 div Angular (45deg) 中的旋转文本会中断。如何永远居中?

javascript - 中心带有百分比值的圆圈显示在不同类别下选中的一组复选框的结果

r - 如何在没有用户交互的情况下更新与 R Shiny 中的 `fileInput` 变量相关的文件?

html - 在 CSS 中调整静态字体大小的工具或方法? (全局相对调整,但保持不变)

Javascript 在特定类出现后在 div 中包装多个 p 标签

javascript - 匹配嵌套 HTML 表格的表格高度

r - 如何在我的 R Shiny 应用程序中显示使用 rcharts 创建的图表?

R Shiny : How to update an input object before a reactive statement gets executed