【问题标题】:Aligning a text with variable length in the middle of dashboard header在仪表板标题中间对齐具有可变长度的文本
【发布时间】:2019-06-23 08:50:58
【问题描述】:

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

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

为了简化代码,我只使用了一个简单的文本,我没有在此处显示我的服务器代码,但是“长度可变的长文本取决于用户选择”基本上是 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) { }
  )

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

使用下面提供的代码,我明白了。

【问题讨论】:

  • 能否请您添加一个代码sn-p。这将帮助我们处理您的代码。谢谢
  • 代码应该在那里,你看不到吗?

标签: html css shiny


【解决方案1】:

试试这样的:

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) {}
)

【讨论】:

  • 谢谢,四个问题: 1- 如何确保文本在标题中也垂直居中? 2-当我最小化屏幕时,标题会中断,因为文本会降低标题的高度。有没有办法解决这个问题?
  • 3- 如果文本由于长度不同而变得太长,则它不适合指定的空间,并且即使在全屏时也会破坏标题。 4- 要获取 css 类 (.main-header .navbar-nav, .main-header .dropdown) ,您在编写初始代码后是否查看 DOM?我想知道修改闪亮外观的最佳方法。我在帖子中添加图片以说明我的意思。
猜你喜欢
  • 1970-01-01
  • 2018-08-05
  • 2018-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-15
  • 2017-05-21
  • 2021-03-21
相关资源
最近更新 更多