Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

renderImage NOT DISPLAYING - R Shiny (only alt text)

Tags:

r

shiny

Using the code below, I am only getting the alt text to appear. Any suggestions on what may be the problem?

From server.R:

output$face <- renderImage({
list(src = "http://www.clipartbest.com/cliparts/yco/GGE/ycoGGEacE.png",
filetype = "image/png",
alt = "YOU MUST BE KIDDING ME!")
}, deleteFile = FALSE)

From ui.R:

imageOutput("face")

Thanks,

Chad

Adding to the explanation of the problem - I am not just trying to display the image. Rather, I am trying to make it reactive - and display a different image, based on inputs... per the server.R code below:

output$imagegauge <- renderImage({
if (is.null(IRR_calc()))
return(NULL)

if (IRR_calc() > .085) {
return(list(
src = "http://www.i2symbol.com/images/abc-123/o/white_smiling_face_u263A_icon_256x256.png",
contentType = "image/png",
alt = "Smiley Face"
))
} else  {
return(list(
src = "http://www.clipartbest.com/cliparts/yco/GGE/ycoGGEacE.png",
filetype = "image/png",
alt = "Sad Face"
))
}
}, deleteFile = FALSE)

Thanks again,

Chad

like image 790
cnblevins Avatar asked Jun 20 '14 17:06

cnblevins


1 Answers

renderImage takes a file as src input rather then a url. You can just include this image directly using tags$img :

library(shiny)
runApp(list(
  ui = fluidPage(
    titlePanel("Hello Shiny!"),
    sidebarLayout(
      sidebarPanel(
        numericInput('n', 'Number of obs', 100),
        numericInput('m', 'Select image (Happy (1) or Sad(2))', 1, min = 1, max = 2),
        uiOutput('test')
      ),
      mainPanel(
        plotOutput('plot')
      )
    )
  ),
  server = function(input, output) {
    output$plot <- renderPlot({ hist(runif(input$n)) })
    output$test <- renderUI({
      images <- c("http://www.i2symbol.com/images/abc-123/o/white_smiling_face_u263A_icon_256x256.png"
                  , "http://www.clipartbest.com/cliparts/yco/GGE/ycoGGEacE.png")
      tags$img(src= images[input$m])

    })
  }
))

enter image description here

like image 170
jdharrison Avatar answered Sep 28 '22 07:09

jdharrison