0

I am trying to incorporate an html page with an image in the top-left into R shiny and call from R studio. The issue is that the img command gets executed when the html file runs displaying the image but when Run in R, I just see a blank image space but no image gets displayed as in the snap below. Attached is the html and R code with snapshot in R. Please help and thank you,

HTML code

<html>
<head><title>
Dashboard
</title>
<meta name="viewport" content="width=device-width,initial-scale=1,user-
scalable=no">
<header>
<img src="C:/D DRIVE DATA/reliance R/Final Template 
/wireframe/www/pepsi.png" height="43" width="145">
</img></header></head></html>

R code

## app.R ##
library(shiny)
library(shinydashboard)
ui= 
dashboardBody(
tags$link(rel="stylesheet", type="text/css",href="bootstrap.css",
htmlTemplate("template.html"
))
)  
server= function(input, output)
{}
shinyApp(ui,server)

enter image description here

enter image description here

Ashmin Kaul
  • 860
  • 2
  • 12
  • 37

1 Answers1

1

When you want to allow a Shiny app to give the user's browser access to images, CSS, etc., those objects needs to be in the www subdirectory of the app (or a further subdirectory of www).

I haven't found a good reference in the documentation for this, but this article on styling Shiny using CSS covers the concept pretty well. Basically you need a www subdirectory in the same directory with your app.R, and then you can reference files within that subdirectory using relative paths.

For example, your app directory may contain

app.R
www/

and www could contain

pepsi.png
some_stylesheet.css
..etc..

then using <img src="pepsi.png" ..> should work.

Brian Stamper
  • 2,143
  • 1
  • 18
  • 41
  • I have done that Sir. Still, it doesn't appear, if i pass it using tags$link, it appears in R but not at the specific position. I want to use html to place it at the needed position. – Ashmin Kaul Oct 03 '17 at 04:44
  • I just made my own test case of this and it worked for me. Are you putting `pepsi.png` in the `www` folder? Note that if you do this the Shiny app will see it, but opening the html directly in your browser it will not, because it won't be looking in `www`. – Brian Stamper Oct 03 '17 at 13:53
  • Hi Brian, regarding this link that you posted, I too have the same query, https://stackoverflow.com/questions/46532497/datatables-apply-column-formatting-to-filter-also, if you figure it out, please help me too. – Ashmin Kaul Oct 05 '17 at 10:55
  • Thank you for your help. – Ashmin Kaul Oct 06 '17 at 09:31