本文介绍了tableHTML闪亮:在单元格中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用tableHTML在闪亮的UI单元中显示图像.但是,它只是显示文本.有帮助吗?

I want to show an image in a shiny UI cell using tableHTML. However, it is simply displaying the text. Any help?

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)
  )}
 )

这是我运行代码后显示的内容:

This is what is shown after I run the code:

推荐答案

这是已知问题tableHTML一起使用,它将在下一发行版中得到修复.目前(您的链接似乎没有指向图片,所以我将使用w3school的图片),您可以使用以下方法:

This is a known issue with tableHTML and it is due to be fixed in the next release. For the time being (your link doesn't seem to point to a picture so I ll use one from w3school) you can use this:

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)
  )}
)

输出:

这篇关于tableHTML闪亮:在单元格中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 03:16