Search code examples
cssrshinyshinydashboard

Adjust height of title in shinydashboard header with logo


I have this code for making my dashboard:

library(shinydashboard)
library(shiny)
library(fresh)
mytheme <- create_theme(
  adminlte_color(
    light_blue = "#004e70"
  ),
  adminlte_sidebar(
    width = "400px",
    dark_bg = "#3c3b3b",
    dark_hover_bg = "#004e70",
    dark_color = "white"
  )
)

Header <- dashboardHeader(
  title = "Labor Market Discrimination in Ecuador",
  titleWidth = 450,
  tags$li(a(img(src = "BID_Blanco.png",
                title = "IDB Logo", height = "60px"),
            tags$style(".sidebar-toggle {height: 70px; padding-top:10px; padding-botton:10px;")),
          class = "dropdown")
)

Tabs <- dashboardSidebar(
  tags$style(".left-side, .main-sidebar {padding-top: 70px}"),
  sidebarMenu(
    menuItem("General", tabName = "general"),
    menuItem("Trial", tabName = "by_trial"),
    menuItem("Sex", tabName = "by_ss")
  )
)

Body <- dashboardBody(
  use_theme(mytheme),
  tabItems(
    tabItem(tabName = "general"),
    tabItem(tabName = "by_trial"),
    tabItem(tabName = "by_ss")
  )
)

ui <- dashboardPage(
  Header, 
  Tabs,
  Body
)

shinyApp(ui, server)

This produces this:

enter image description here

What can I do to make the title taller (where does it say "Labor Market Discrimination in Ecuador")? like the same height as the blue bar where the logo is

and to get rid of the black space where my tabs start? (just above "general") This is one of my very first shinydashboards, so I'm a bit lost.


Solution

  • You need to specify a height to the .logo span (make sure to address the <span> with enough specificity to make sure your rule eventually applies):

    Body <- dashboardBody(
      use_theme(mytheme),
      tags$head(
        tags$style("
           .left-side, .main-sidebar {
              padding-top: 70px;
           }
           .skin-blue .main-header .logo {
              height: 70px; 
              display: inline-flex;
              align-items: center;
           }")
         ),
      tabItems(
        tabItem(tabName = "general"),
        tabItem(tabName = "by_trial"),
        tabItem(tabName = "by_ss")
      )
    )
    

    Header of a Shinydashboard Page wiht the logo span spanning the whole area of the surrounding header tag