Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Shiny img() on UI side does not render the image

Tags:

r

shiny

I have a static image in the local folder I am trying to render in the Shiny UI and it does not work. Shows a broken image with a question mark in the middle.

ui <- fluidPage(img(src = 'imagefile.png', height = '100px', width = '100px'))
server <- function(input, output) {}
shinyApp(ui = ui, server = server)

Any idea what is going on?

like image 928
Gopala Avatar asked Mar 02 '16 23:03

Gopala


People also ask

Why is the image not showing for R shiny?

It's just the image-display that is faulty. 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 Answers

Put the image in a folder called www in the same directory, so you have www/imagefile.png. Then, call

library(shiny)
ui <- fluidPage(img(src = 'imagefile.png', height = '100px', width = '100px'))
server <- function(input, output) {}
shinyAppDir(".")

But, you probably want to be using runApp with a separate ui and server file.

like image 187
Rorschach Avatar answered Sep 18 '22 20:09

Rorschach