Search code examples
rshinyshinydashboard

How to prevent code for adding an image to ShinyDashboard header appearing in browser tab?


I have added code to display a logo in the header of a shinydashboard app I am working on. The image displays as I hoped but the code is appearing within the sheet tab of the internet browser which is obviously not ideal, is there a way to prevent this from happening?

Example Image

The relevant line of code I have used is:

dashboardHeader(title = tags$a(tags$img(src = "/MainLogo.png", align = "left")))

A full working example is given below (image file located in 'www' folder within the app project folder).

## app.R ##
library(shiny)
library(shinydashboard)

ui <- dashboardPage(

  dashboardHeader(title = tags$a(tags$img(src = "/MainLogo.png", align = "left"))),

  dashboardSidebar(),
  dashboardBody(
    # Boxes need to be put in a row (or column)
    fluidRow(
      box(plotOutput("plot1", height = 250)),

      box(
        title = "Controls",
        sliderInput("slider", "Number of observations:", 1, 100, 50)
      )
    )
  )
)

server <- function(input, output) {
  set.seed(122)
  histdata <- rnorm(500)

  output$plot1 <- renderPlot({
    data <- histdata[seq_len(input$slider)]
    hist(data)
  })
}

shinyApp(ui, server)

Solution

  • I have run into the same issue before, I hope this works for you. I had to look back at a previous application, and this was under my sidebar environment in the ui.R, you may need to play around with where it is placed, but it should work.

    HTML('<script> document.title = "Internet Tab Name"; </script>')