Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Shiny display output externally hosted image

Tags:

r

shiny

I have a Shiny app that returns a character string containing the direct URL to an image hosted on the web. I am trying to find a way to display this image directly as an output.

When using renderImage() with src = "image url" the app does not display the image.

Here is an example of the problem:

ui.R

library(shiny)

shinyUI(fluidPage(
  headerPanel("render externally hosted Image example"),

  mainPanel(
   # Use imageOutput to place the image on the page
   imageOutput("myImage")
  )
))

server.R

library(shiny)

shinyServer(function(input, output, session) {
  output$myImage <- renderImage({
    list(src = "http://data-informed.com/wp-content/uploads/2013/11/R-language-logo-224x136.png",
     contentType = 'image/png',
     width = 224,
     height = 136,
     alt = "This is image alternate text")
  })
})

Any help is appreciated!

like image 380
Kyle Bao Avatar asked Feb 26 '16 12:02

Kyle Bao


1 Answers

You could use htmlOutput() in the ui and renderText() in server.

Server.r

src = "https://theWeb/aPictureSomewhere.jpg"
output$picture<-renderText({c('<img src="',src,'">')})

ui.r

htmlOutput("picture")
like image 64
user5219763 Avatar answered Nov 08 '22 00:11

user5219763