-
-
Save ramnathv/f476dd3751e672a96801 to your computer and use it in GitHub Desktop.
require(shiny) | |
shinyServer(function(input, output){ | |
output$mytable <- renderTable({ | |
dat <- data.frame( | |
country = c('USA', 'China'), | |
flag = c('<img src="http://upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/200px-Flag_of_the_United_States.svg.png"></img>', '<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Flag_of_the_People%27s_Republic_of_China.svg/200px-Flag_of_the_People%27s_Republic_of_China.svg.png"></img>') | |
) | |
dat | |
}, sanitize.text.function = function(x) x) | |
}) |
require(shiny) | |
shinyUI( | |
tableOutput('mytable') | |
) |
Nevermind -- I figured it out! :)
Thanks for this. I've been struggling with getting images into a table for days now!
This allows me to get a fixed image into a table, but how do you make this variable, i.e. dependent on a column of the table?
I have a simple app that effectively subsets a data frame depending on what the user is looking for. For each row of data, there is an image saved in a folder named "www" in the directory, as instructted in the Shiny tutorial. The images are saved as "the-first-column-of-the-dataset.JPG". Below is the Server.R code I'm working with:
CPdata <- read.csv("data/Inventory Data Update 3.csv",
check.names = F,
stringsAsFactors = F)
library(shiny)
shinyServer(function(input, output) {
output$result <- renderTable({
if(input$enter1 != "" & input$enter2 != "")
{x <- subset(CPdata,
grepl(tolower(input$enter1), tolower(CPdata[, input$search])),
c(names(CPdata)[1], input$search, if(input$enter2 != "")
{names(CPdata)[grepl(tolower(input$enter2), tolower(names(CPdata)))]}))
pic <- paste(x[,1], ".JPG", sep = "")
if(input$search != names(CPdata)[1])
{df <- data.frame("Inventory Number" = x[,1],
subset(CPdata,
grepl(tolower(input$enter1), tolower(CPdata[, input$search])),
c(input$search, if(input$enter2 != "")
{names(CPdata)[grepl(tolower(input$enter2), tolower(names(CPdata)))]})),
Work = '<img src=pic.JPG></img>',
row.names = NULL,
check.names = F)
df}
else
{df <- data.frame(subset(CPdata,
CPdata[,input$search] == input$enter1,
c(input$search, if(input$enter2 != "")
{names(CPdata)[grepl(tolower(input$enter2), tolower(names(CPdata)))]})),
Work = '<img src=pic.JPG></img>',
row.names = NULL,
check.names = F)}}
}, sanitize.text.function = function(x) x)
})
on line 21 I tried to create the variable "pic" and place it in the html code in the "Work" column of the data frame. Since the html code is wrapped in quotes, it simply reads this as "pic.JPG", rather than "value-of-pic.JPG".
If anyone can shine some lighy on how I do this, it'd be much appreciated!!
Thanks,
Mike
Hi there,
I managed to solve this with the qq function, a Perl like function in the GetoptLong package on variable interpolation within text strings.
Thanks,
Mike
it's really helpful for me , Thank you so much
Thanks a lot! Great trick!
Brilliant!
Is it possible to make this work with
reactive
given that youcannot coerce class ""reactive"" to a data.frame
?I was trying this...
with this