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 titl...

问题:

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

enter image description here

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?


回答1:

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.


回答2:

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".

  • 发表于 2020-06-27 21:49
  • 阅读 ( 143 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除