0

Currently I am running Shiny app locally and trying to display a PNG image (Name : download.png), which is saved locally in the 'www' folder under my Working directory.

Now I want to display that image in my Browser locally, so I have below simple code (please note that I didnt save below code in my disk, I just have written this code and sitting in my R code editor - Sublime Text) :

runApp(list(
  ui = fluidPage(
   tags$img(src = 'www/download.png')
  ),
  server = function(input, output) {
  }
))

However unfortunately above code could not display the image in the Browser. However R could affirm availability of the file :

> file.exists('www/download.png')
[1] TRUE

Can someone confirm where I went wrong?

Soma
  • 123
  • 2
  • 6
  • Possible duplicate of [How to print file to Shiny using renderText](http://stackoverflow.com/questions/42008543/how-to-print-file-to-shiny-using-rendertext) – HubertL May 17 '17 at 22:25
  • If the issue is that you haven't saved the code and/or you're trying to launch the app from Sublime Text, the answer from @LyzandeR is your answer. I'd suggest using RStudio instead, it makes development (Shiny and other) much easier. – neilfws May 17 '17 at 22:48

1 Answers1

3

You can do the following, instead of having your code in your text editor:

  1. Add the following to the ui.r file:

    fluidPage(
     #notice that you don't need to use www/download.png - shiny knows
     #that it needs to look in www/
     tags$img(src = 'download.png')
    )
    
  2. Add the following to the server.r file:

    function(input, output){}
    
  3. Navigate to the directory where server.r, ui.r and www/ are (using setwd() on the R console for example) and run:

    runApp()
    

And this will work.

I am not sure why runApp(list(ui = , server = )) does not work (probably shiny does not parse www/), but using the files will work just fine.

LyzandeR
  • 37,047
  • 12
  • 77
  • 87