0

I am working on a Shiny app that gets information from an API and displays that information in a table. Here is the code I have right now:

  output$ItemInfo <- renderTable({

    base <- "http://services.runescape.com/m=itemdb_rs/api/catalogue/detail.json?item="
    item.id <- item.codes %>% filter(name == input$item)
    url <- paste0(base, item.id$id)
    item.data <- fromJSON(url)

    table.data <- runescape.data %>% filter(ItemName == input$item)
    image.url <- item.data[[1]]$icon_large[1]
    Info <- c('Description', 'Image', 'Current Price (GP)', '% Change in Last 30 Days', '% Change in Last 90 Days', '% Change in Last 180 Days', 'Members Only', 'Low Alch', 'High Alch')
    Data <- c(item.data[[1]]$description[[1]], paste0('<img src="', image.url, '"></img>'), item.data[[1]]$current$price, item.data[[1]]$day30$change, item.data[[1]]$day90$change, item.data[[1]]$day180$change, table.data$MembersOnly[[1]], table.data$LowAlch[[1]], 
          table.data$HighAlch[[1]])

    #Display Both columns
    return(data.frame(Info, Data))
  })

I am getting a correct image.url, I just cannot figure out how to render it. Currently this just displays code like <img src="http://services.runescape.com/m=itemdb_rs/1480946739712_obj_big.gif?id=560"></img> where the actual image should be.

I also tried using this code as a replacement for the paste0 bit in on the Data line: img(src='http://services.runescape.com/m=itemdb_rs/1480946739712_obj_big.gif?id=560', width = '300px', height = '100px'), but this broke the entire table for some reason.

How can I go about rendering the images I get from this URL?

Kyle
  • 169
  • 7
  • Did you take a look at this: http://stackoverflow.com/questions/30671958/how-to-embed-an-image-in-a-cell-a-table-using-dt-r-and-shiny? – Gopala Dec 06 '16 at 00:17
  • I did see that, however the syntax on that post is very confusing to me. I'm working on this project for a class and we haven't been taught about this double colon syntax, like `DT::renderDataTable` so I'm not sure how to incorporate that into my code. – Kyle Dec 06 '16 at 00:33
  • That is a package called `DT` that goes along with Shiny and allows much richer presentation of tables. `DT::` just means use the render function from the `DT` package. – Gopala Dec 06 '16 at 00:34
  • Do you know if I have to use the DT package to get this to work, or is there a way to do it with just the standard Shiny package? – Kyle Dec 06 '16 at 00:39
  • I never use the basic `renderTable`. So, I don't know. Others may chime in. – Gopala Dec 06 '16 at 00:51
  • `HTML(paste0(''))` – Michael Griffiths Dec 06 '16 at 01:59

0 Answers0