【问题标题】:How to Centre the titlePanel in Shiny?如何在 Shiny 中将 titlePanel 居中?
【发布时间】:2018-07-12 05:52:05
【问题描述】:

在R的Shiny包中,如何让titlePanel中的文字在页面顶部居中?

Here is an example of what I mean

我用于 titlePanel 的唯一代码是:

ui <- fluidPage(
  titlePanel("How to Centre Me??")

当我查看文档时,函数采用的唯一变量是:

titlePanel(title, windowTitle = title)

那么可以让标题居中吗?

谢谢

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    如果有人仍然需要一个简单的解决方案:

    titlePanel(
        h1("First level title", align = "center")
    )
    

    【讨论】:

      【解决方案2】:

      你可以使用 column() 函数。

      像这样:

      fluidPage(
                 column(3,offset = 4, titlePanel("How to Centre Me??")) 
                 )
      

      其中 3 是列宽和偏移量,您可以根据需要进行调整。

      【讨论】:

        【解决方案3】:

        使用 css:

        ui <- fluidPage(
          tags$head(
            tags$style(
              ".title {margin: auto; width: 200px}"
            )
          ),
          tags$div(class="title", titlePanel("Centered title"))
        )
        

        【讨论】:

          【解决方案4】:

          或者您可以放弃通常位于侧边栏中心的 titlePanel() 并执行以下操作:

              titlePanel(""),
          
              sidebarLayout(
                  sidebarPanel(
                  ),
          
                  mainPanel(
                     h1("This is my title now")
                  )
          

          不优雅但非常简单。

          【讨论】:

            猜你喜欢
            • 2019-01-28
            • 2017-01-30
            • 1970-01-01
            • 2019-05-04
            • 2020-11-24
            • 2014-09-28
            • 2020-04-01
            • 2022-06-10
            • 2019-01-22
            相关资源
            最近更新 更多