2017-07-24 152 views
2

我想使用tableHTML在闪亮的UI单元格中显示图像。但是,它只是显示文本。任何帮助?tableHTML闪亮:在单元格中显示图像

library(shiny) 
a = data.frame(rows = 1:2, icons = '<img src = 
    "http://flaglane.com/download/american-flag/american-flag-graphic.png" 
    alt="Red Flag Warning" height="30" width="40" >') 



    shinyApp(
    ui = fluidPage(
     fluidRow(

    br(), 
    column(width = 1), 
    tableHTML_output("mytable")) 
    ), 
server = function(input, output) { 
    output$mytable <- render_tableHTML( 
    tableHTML(a) 
)} 
) 

这是在我运行的代码显示的内容: enter image description here

回答

3

这是一个known issuetableHTML,这是由于固定在下一版本中。暂且(你的链接似乎并不指向图片,所以我将使用一个来自w3school),你可以使用这个:

library(shiny) 
library(tableHTML) 
a = data.frame(rows = 1:2, icons = '<img src = 
       "https://www.w3schools.com/images/w3schools_green.jpg" 
       alt="Red Flag Warning" height="30" width="40" >') 



shinyApp(
ui = fluidPage(
    fluidRow(

    br(), 
    column(width = 1), 
    tableHTML_output("mytable")) 

), 
server = function(input, output) { 
    output$mytable <- render_tableHTML( 
    tableHTML(a) %>% 
    replace_html(pattern = '&#60;', '<', replace_all = TRUE) %>% 
    replace_html(pattern = '&#62;', '>', replace_all = TRUE) 
)} 
) 

输出:

enter image description here