Embedding Image in Shiny App
I've been working on a shiny app and would like to include a logo in the upper right corner of the app. How can I easily embed an image using shiny and r?
Thanks! K
Solution 1:
I found another option that looks good for this app, so I'm sharing for others who want the image in the mainPanel.
mainPanel(
img(src='myImage.png', align = "right"),
### the rest of your code
)
Save the file in a www directory in the shinyApp directory:
| shinyApp/
| ui.R
| server.R
| www/
| myImage.png
Solution 2:
Use a custom header function in ui.R
to reference an app.css
file in your www/
directory:
customHeaderPanel <- function(title,windowTitle=title){
tagList(
tags$head(
tags$title(windowTitle),
tags$link(rel="stylesheet", type="text/css",
href="app.css"),
tags$h1(a(href="www.someURLlogoLinksto.com"))
)
)
}
In app.css
reference the logo file also located in your www/
folder:
h1 {
text-decoration:none;
border:0;
width : 550px;
height : 50px;
margin : 0;
padding : 0;
left: 25px;
top: 5px;
position: relative;
background : url(logo.png) no-repeat 0 0;
}