Image not showing R Shiny (displayed as broken)

Hi,

I am trying to add a logo to my dashboard-header with the following code:

title <- tags$a(href='https://google.com',
                tags$img(src='logo.png'))

header <- dashboardHeader( title = title, uiOutput("logoutbtn"), titleWidth = 400)

The following is displayed instead of my logo.
image

I have tried the following:

  • Named my file app.R
  • Saved the "logo.png"-file in a subfolder called www
  • Pressed the Run App-button
  • Looked through many topics in the rstudio-community and on stackoverflow.

Can anyone help me? Please let me know if I have shared to little of code or anything else.

Thanks!! :smile:

1 Like

I was able to reproduce similar issue if i clicked the 'Run App' button, but if I use runApp() directly in the concole, the picture can be displayed as expected, not sure why though...

ps. my current working directory is the same as the file path of app.R

library(shiny)
library(shinydashboard)

title <- tags$a(href='https://google.com',
                tags$img(src='b.jpg', width='100px',height='100px')) # an image downloaded from web (b.jpg under www folder)
                

header <- dashboardHeader( title = title, uiOutput("logoutbtn"))

ui <- dashboardPage(header, dashboardSidebar(), dashboardBody())


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

}

shinyApp(ui, server)

Thank you for replying @ifendo ! I tried running the runApp()-function directly in the console, but it still does not work for me. Otherwise my code seems to be exactly the same as yours.

Could it perhaps be some updates I need to do?

By the way: the link works just fine. It's just the image-display that is faulty.

1 Like

By default, RStudio searches in the 'www' folder. Try creating such a folder and place your image file in there. Make sure you still use the same path without 'www' for the src.

1 Like

@frida facing the same issue.
It can display images from web links, but not from the local "www" foder.

@Thomas_Thurnherr static files are placed in "www" folder only, and the src path excludes "www". Seems like the static resource isn't available and giving 404. Found below error in Inspect Element -> console

This issue got fixed by simply running the app externally.
Click on drop-down icon beside the "Run App" button and choose "Run External".

image

FYI, Default static file path for R shiny apps: "www" in app root directory.

1 Like

@mdamircoder
I have the same issue! Running externally doesn't solve the problem though, with Firefox as well as Chromium.
Interestingly, functions such as includeMarkdown, sourcing from the same directory, seem to work correctly.

Edit : it was using shinyApp instead of runApp that was causing the app not to find the www folder.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.