简体   繁体   中英

R shiny - Add logo in browser window using titlePanel

I want to add a logo to the browser window in the same way as all browser windows are usually displayed:

在此处输入图像描述

titlePanel allows to add easily images to the application title, by using: titlePanel(title = div(img(src="myAppImage.jpg"), "My App Name") It is also possible to add the title that should be displayed by the browser window with windowTitle as a parameter.

However, it does not work when adding an image to the browser window. I tried: titlePanel(title = div(img(src="myAppImage.jpg"), "My App Name"), windowTitle = div(img(src="myBrowserImage.png"), "My Browser Name")) . But this gives the following browser name: <img src...>

What is the correct way of writing it?

Not inside the titlePanel but you can add following inside the ui:

tags$head(
        tags$link(rel = "icon", type = "image/png", sizes = "32x32", href = "/myBrowserImage.png"))

Also you should put the image inside www folder.

As @phago29 indicated, one way to write it is:

  useShinyjs(),
  
  ## Window title
  tags$head(
    tags$link(rel = "icon", type = "image/png", sizes = "32x32", href = "myBrowserImage.png")),
  
  # App title ----
  titlePanel( title =  div(img(src="myAppImage.png"), 'myAppTitle'), windowTitle = "myBrowserTitle" ), 
  
  # Rest of the UI
) 

With the png images in a subfolder called "www".

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