闪亮面板标题中的换行或换行

时间:2019-04-08 17:15:13

标签: r shiny shinydashboard

我使用的是shinydashboard,但是标题太长时,它不能换行。我尝试使用<br/>来完成此操作,但是即使在这种情况下,HTML()也无法使用。

我知道我可以使用titleWidth来扩大标题空间,但这在很多情况下看起来并不理想。

最简单的方法是什么?

这是一个例子:

library(shiny)
library(shinydashboard)

## Only run this example in interactive R sessions
if (interactive()) {
    header <- dashboardHeader(title = "This title is just way too long")

    sidebar <- dashboardSidebar(
        sidebarUserPanel("User Name",
                         subtitle = a(href = "#", icon("circle", class = "text-success"), "Online"),
                         # Image file should be in www/ subdir
                         image = "userimage.png"
        ),
        sidebarSearchForm(label = "Enter a number", "searchText", "searchButton"),
        sidebarMenu(
            # Setting id makes input$tabs give the tabName of currently-selected tab
            id = "tabs",
            menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
            menuItem("Widgets", icon = icon("th"), tabName = "widgets", badgeLabel = "new",
                     badgeColor = "green"),
            menuItem("Charts", icon = icon("bar-chart-o"),
                     menuSubItem("Sub-item 1", tabName = "subitem1"),
                     menuSubItem("Sub-item 2", tabName = "subitem2")
            )
        )
    )

    body <- dashboardBody(
        tabItems(
            tabItem("dashboard",
                    div(p("Dashboard tab content"))
            ),
            tabItem("widgets",
                    "Widgets tab content"
            ),
            tabItem("subitem1",
                    "Sub-item 1 tab content"
            ),
            tabItem("subitem2",
                    "Sub-item 2 tab content"
            )
        )
    )

    shinyApp(
        ui = dashboardPage(header, sidebar, body),
        server = function(input, output) { }
    )
}

目标是应用自动换行,以便我们可以阅读整个标题(显示"This title is just way too long")。

1 个答案:

答案 0 :(得分:2)

header <- dashboardHeader(title = h4(HTML("This title<br/>is just way too long")))

shinyApp(
  ui = dashboardPage(header, sidebar, body),
  server = function(input, output) { }
)

enter image description here