Search code examples
cssrshinynavbar

Size of Shiny Navbar title row changes when resizing window


How can I get rid of the space below the Navbar title that appears when the window is resized to a smaller size? In the screenshots below, the height of the grey title row seems to be twice as large. Code for a minimal example is below. The change seems to happen at a width of 600px.

App in large window

App in small window

library(shiny)

ui <- navbarPage(
  title = "Title", id = "navbar", 
  tabsetPanel(id="tabs", 
              tabPanel(value = "tab1", title = "Tab1"),
              tabPanel(value = "tab2", title = "Tab2")
  )
)

server <- function(input, output, session) {
}

shinyApp(ui, server)

Solution

  • You can set position: absolute; for your navbar and it will not change below 600px.

    library(shiny)
    
    ui <- navbarPage(
        tags$head(tags$style(HTML("
                                  #navbar {
                                    position: absolute;
                                  }
                                  "))),
        title = "Title", id = "navbar", 
        tabsetPanel(id="tabs", 
                    tabPanel(value = "tab1", title = "Tab1"),
                    tabPanel(value = "tab2", title = "Tab2")
        )
    )
    
    server <- function(input, output, session) {
    }
    
    shinyApp(ui, server)