shinydashboard 标题中的自动换行或换行符

Word-wrapping or new line in shinydashboard title

提问人:Hack-R 提问时间:4/9/2019 最后编辑:Hack-R 更新时间:4/9/2019 访问量:2546

问:

我正在使用 但是当标题太长时,它无法换行。我曾尝试过使用它来实现这一点,但在这种情况下,即使围绕它也不起作用。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"

R 亮闪 亮仪表板

评论


答:

8赞 Aurèle 4/9/2019 #1
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

评论

0赞 Hack-R 4/9/2019
谢谢!不知何故,我尝试了该解决方案的每个元素,但没有正确的组合