Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place an image in an R Shiny title

Tags:

r

shiny

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

like image 865
RustyStatistician Avatar asked Mar 23 '16 15:03

RustyStatistician


1 Answers

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(
    )
  )
)
)

enter image description here

like image 196
Paul Govan Avatar answered Sep 28 '22 08:09

Paul Govan