简体   繁体   中英

Add image and title in the same row of the header section of a shiny dashboard

I create a shiny dashboard in which I have set titleWidth and sidebar width = 0 in order to have them hidden. Then I want to add an image in the left corner of the header section which will completely fit to the header section and then the title in the same row but in the right corner. As you can see now the header section became bigger and also the title seems to be a row lower than the image. Here is my code:

在此处输入图片说明

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
dbHeader <- dashboardHeaderPlus(
    titleWidth = "0px",
    tags$li(a(href = 'http://https://www.uow.edu.au/',
              img(src = 'download.png',
                  height = "55px",width="232px"),
              style = "padding-top:0px; padding-bottom:0px; padding-right:1690px;padding-left:90px;"),
            class = "dropdown")
    
)
shinyApp(
    ui = dashboardPagePlus(
        header = dbHeader,
        sidebar = dashboardSidebar(width = "0px"),
        body = dashboardBody(
            useShinyjs(),
            
            tags$head(tags$style(".skin-blue .main-header .logo { padding: 0px;}")),
            
            tags$head(tags$style(HTML(
                '.myClass { 
        font-size: 25px;
        line-height: 50px;
        text-align: left;
        font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
        padding:  1500px;
        padding-bottom: 0 0px;
        padding-top: 0 0px;

        overflow: hidden;
        color: black;
      }
    '))),
            tags$script(HTML('
      $(document).ready(function() {
        $("header").find("nav").append(\'<span class="myClass"> Life,Death & Statins </span>\');
      })
     '))
            
            
            
        )
        
    ),
    server<-shinyServer(function(input, output,session) { 
        hide(selector = "body > div > header > nav > a")
        
    }
    )
)

Perhaps your are looking for this. You can play with padding and margins to get appropriate spacing.

mytitle <- paste0("Life, Death and Statins")

dbHeader <- dashboardHeaderPlus(
  titleWidth = "0px",

  tags$li(a(href = "https://www.mit.edu/", #   'http://https://www.uow.edu.au/',
            div(style = "margin-left:-15px;margin-bottom:-44px;margin-top:-15px;padding: 0px 1190px 0px 0px ; width: 290px;",
                img(src = 'YBS.png', height = "55px",width="232px")),
            div(style="display: inline; padding: 0px 90px 0px 750px ; font-size: 40px ; width: 300px;",HTML(mytitle, "<br>"))
            ),
          class = "dropdown")
)

输出

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