How to place an image in an R Shiny title

喜欢而已 提交于 2020-01-01 09:04:18

问题


So I am using R Shiny and I want to place an image to the right of the text in the title. I can seem to place the image anywhere in the application with the exception of next to the title. Can you not place images in the titlePanel() function? Here is a snippet of the code that I am using:

library(shiny)

# Define UI for random distribution application 
shinyUI(fluidPage(#theme="bootstrap.css",

  # Application title
  titlePanel("My Title",img(src = "picture.jpg", height = 50, width = 100)),
  sidebarLayout(
    sidebarPanel(

So when I use the above code I can't seem to see my image anywhere in the app....


回答1:


One way would be to follow the directions in this post: How can I insert an image into the navbar on a shiny navbarPage() (The SO hounds would attack this as a duplicate).

Create a folder called 'www' in your working directory and place 'picture.jpg' inside as so:

| shinyApp/
    | ui.R
    | server.R
 | www/
    | picture.png

Include your picture in titlePanel with a div:

ui.r

library(shiny)

# Define UI for random distribution application 
shinyUI(fluidPage(#theme="bootstrap.css",

  # Application title
  titlePanel(title=div(img(src="picture.jpg"), "My Title")),
  sidebarLayout(
    sidebarPanel(
    )
  )
)
)



来源:https://stackoverflow.com/questions/36182535/how-to-place-an-image-in-an-r-shiny-title

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!