8

I am having trouble displaying an image in a Shiny app. The code is saved in Desktop, where I also have a www folder with logo.png. I've set the working directory to the desktop, as well:

library(shiny)
library(png)

ui <- fluidPage(
  img(src="logo.png", height = 400, width = 400)
) #close fluidpage


server <- function(input, output, session){

} # closer server

shinyApp(ui=ui, server=server)

Here's how the output looks.
enter image description here

I prefer to have server and ui in the same file for ease of understanding. Perhaps that is the issue?

SymbolixAU
  • 25,502
  • 4
  • 67
  • 139
matsuo_basho
  • 2,833
  • 8
  • 26
  • 47
  • Does it display if you open it in browser? – SymbolixAU Apr 24 '16 at 01:28
  • This is odd. I've tried splitting server.R & ui.R, and [the documentation/guides](http://shiny.rstudio.com/tutorial/lesson2/) say this is how it's done... – SymbolixAU Apr 25 '16 at 07:01
  • Not sure why this is the case, but it seems like it works if you are in a different working directory `(getwd() != )` and then execute `runApp("appdir")` from your console. Slightly more information on single-file Shiny Apps can be found [here](http://shiny.rstudio.com/articles/single-file.html) although this particular issue with images isn't addressed – tauculator Apr 25 '16 at 09:37
  • That hack works, but it breaks an excel sheet import I have using a fileInput widget and the readXL library. – matsuo_basho Apr 25 '16 at 13:16

2 Answers2

6

Similar Shiny img problem solved here. Rather than executing the code directly or in console, creating a properly formatted app.R and clicking Run App seems to work.

deduciver
  • 101
  • 1
  • 5
0

If you just want to display your image. You can give a handson with HTML on Rshiny. Below is the modified code, which you can try. Hope it works

library(shiny)
library(png)

ui <- fluidPage(
 headerPanel(
  list(tags$head(tags$style()), 
     HTML('<img src="logo.png", height="400px"    
          style="float:right"/>','<p style="color:black"></p>')
         )#headerPanel closes
        ) #close fluidpage


       server <- function(input, output, session){

       } # closer server

       shinyApp(ui=ui, server=server)
Shalini Baranwal
  • 2,780
  • 4
  • 24
  • 34