How can I embed an image in a cell that is generated using the DT package so that it is displayed in an app using shiny?
如何在使用DT包生成的单元格中嵌入图像,使其在应用程序中使用闪亮显示?
My example is based of this question R shiny: How do I put local images in shiny tables
我的例子基于这个问题R闪亮:如何将本地图像放在闪亮的表中
The example code below doesn't display the image, but rather just the url.
下面的示例代码不显示图像,而是显示url。
# ui.R
require(shiny)
library(DT)
shinyUI(
DT::dataTableOutput('mytable')
)
# Server.R
library(shiny)
library(DT)
dat <- data.frame(
country = c('USA', 'China'),
flag = c('<img src="test.png" height="52"></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" height="52"></img>'
)
)
shinyServer(function(input, output){
output$mytable <- DT::renderDataTable({
DT::datatable(dat)
})
})
1 个解决方案
#1
20
You can use the escape = FALSE
in your DT call, as per: https://rstudio.github.io/DT/#escaping-table-content
您可以在您的DT调用中使用escape = FALSE,如:https://rstudio.github.io/dt/# escapingtable -content。
# ui.R
require(shiny)
library(DT)
shinyUI(
DT::dataTableOutput('mytable')
)
# Server.R
library(shiny)
library(DT)
dat <- data.frame(
country = c('USA', 'China'),
flag = c('<img src="test.png" height="52"></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" height="52"></img>'
)
)
shinyServer(function(input, output){
output$mytable <- DT::renderDataTable({
DT::datatable(dat, escape = FALSE) # HERE
})
})
#1
20
You can use the escape = FALSE
in your DT call, as per: https://rstudio.github.io/DT/#escaping-table-content
您可以在您的DT调用中使用escape = FALSE,如:https://rstudio.github.io/dt/# escapingtable -content。
# ui.R
require(shiny)
library(DT)
shinyUI(
DT::dataTableOutput('mytable')
)
# Server.R
library(shiny)
library(DT)
dat <- data.frame(
country = c('USA', 'China'),
flag = c('<img src="test.png" height="52"></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" height="52"></img>'
)
)
shinyServer(function(input, output){
output$mytable <- DT::renderDataTable({
DT::datatable(dat, escape = FALSE) # HERE
})
})