17

I have an image i'd like to embed into my shiny app, and have read as much as I can find on how to do it. Although, all I get is a blue question mark when I run my code.

This is the line of code I have added, within the fluidPage ui command

img(src="logo.png", align = "right",height='100px',width='400px')

My image has been placed in the project directory folder, as well as trying in a separate folder inside named www (as per suggestion given here)

EDIT: Code used in the following context:

ui <- fluidPage(titlePanel("Test title"),

                img(src="logo.png", align = "right",height='100px',width='400px'),

                hr())
zx8754
  • 52,746
  • 12
  • 114
  • 209
sym246
  • 1,836
  • 3
  • 24
  • 50
  • I've just checked that adding the code above to e.g. `sidebarPanel` inside `sidebarLayout` in `fluidPage` and placing the image in `www/logo.png` works just fine. Can you maybe share the code of the particular app which fails for you? Thanks! – aoles Jun 24 '16 at 16:13
  • I added the line of code inside fluidPage, after titlePanel. I have added a more comprehensive example in the OP. – sym246 Jun 27 '16 at 08:42
  • This seems to work for me, see `runGitHub("aoles/SO_38011285")`. Maybe you have a typo in the image path, or some other problem with the image file itself? – aoles Jun 27 '16 at 09:38
  • 2
    Possibly. Its a mystery to me since yours works fine, yet mine will not show. The image path should be fine since the directory is set as the R project folder where the .app file is kept. Strange! – sym246 Jun 28 '16 at 10:55
  • I have same issue. No rendering when using `img()` on the ui side. Using identical path but rendering from the server side works fine. – hartmut Jun 26 '17 at 07:45

4 Answers4

27

After coming back to this problem, I found that the solution is to simply format the Shiny code properly, by naming the R file app.R, and clicking Run App as opposed to selecting all of the code and running within the console.

Not sure how or why this makes a difference, but the numerous Shiny applications I have worked on since have all been resolved when doing this.

sym246
  • 1,836
  • 3
  • 24
  • 50
  • 8
    WOW. just wow. I have spent the whole morning troubleshooting this trivial error. Checking multiple times the image address, the www folder, the app name, the code and what not. I even placed the image at various places to see if that works. AND THEN THIS ANSWER. I would not have guessed this in 100 or 1000 tries. I believe this should be reported at R Shiny Github repo. May all the lost people find there way here quicker than I did. – Urvah Shabbir Jul 10 '18 at 10:54
  • Glad I was able to help :). This problem caused me a huge headache so glad it helped you – sym246 Jul 11 '18 at 11:14
  • 1
    Thank you so much @sym246 . You saved me so much agony –  Jan 30 '19 at 04:53
  • @sym246, very important issue you clarified. Has anyone opened an issue on github about that? – GitHunter0 Aug 07 '20 at 20:07
  • I hadn’t opened one, no. Not sure if anyone else has. – sym246 Aug 08 '20 at 22:11
  • This problem costed a few hours of my time as well. Another thing you shouldn't do is to (out)source the ui/server code to another file in another folder. – Rumpl Jul 04 '22 at 08:49
5

Just a note that may be helpful to someone else, it just happened to me: please double check if your app.R is in the root directory. I.e, app.R is on the same level as the www folder. I know it seems trivial, but if you (as I just did) put app.R into a subfolder and click Run App, the app can still run, just without the pictures.

Yang Liu
  • 521
  • 6
  • 4
3

I was having the same problem. To solve this, just create a folder named 'www' in the same folder as your app.R script and put the images within that folder.

I found the solution to this problem in the tutorial video in this page: Shiny Tutorial Video - Adding Static Content Watch from 1h45min00sec.

gurezende
  • 176
  • 9
  • This didn’t work (as per the suggestion in the OP). There seems to be a glitch when selecting the code and running it this way, as opposed to clicking ‘Run App’ – sym246 Aug 25 '20 at 14:56
0

You should check if the name of your R code file is called “app.R" instead of called xxx.R. this error also happened to me

yuanzz
  • 1,359
  • 12
  • 15