簡體   English   中英

如何在 Shiny 中將 titlePanel 居中?

[英]How to Centre the titlePanel in Shiny?

在 R 的 Shiny 包中,如何讓 titlePanel 中的文本在頁面頂部居中?

這是我的意思的一個例子

我用於 titlePanel 的唯一代碼是:

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

當我查看文檔時,該函數采用的唯一變量是:

titlePanel(title, windowTitle = title)

那么可以將標題居中嗎?

謝謝

如果有人仍然需要一個簡單的解決方案:

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

您可以使用 column() 函數。

像這樣:

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

其中 3 是列寬和偏移量,您可以根據需要進行調整。

使用CSS:

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

或者你可以放棄通常以側邊欄為中心的 titlePanel() 並執行以下操作:

    titlePanel(""),

    sidebarLayout(
        sidebarPanel(
        ),

        mainPanel(
           h1("This is my title now")
        )

不優雅,但非常簡單。

如果您使用的是 navbarPage() 您應該使用header=h1("title",align="center")和 footer('same syntax as header') 參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM