简体   繁体   中英

Word-wrapping or new line in shinydashboard title

I'm using a shinydashboard but when the title is too long it fails to wrap the lines. I have tried using <br/> to accomplish this, but it doesn't work even with HTML() around it in this context.

I know I can make the title space wider with titleWidth , but that does not look as good in many cases.

What would be the simplest way to achieve this?

Here's an example:

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

The goal is to apply word-wrapping so that we can read the entire title (which says "This title is just way too long" ).

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

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

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM