R闪亮:如何将本地图像放在闪亮的表格中

问题描述:

如果图像存储在我的机器上,我似乎无法在表格中显示图像。如果图像是由URL指定的,我可以让它工作,但我不知道任何简单的方法来提供图像,以便可以通过URL找到它,而不是仅仅使用图像文件名并放置文件在与ui.R和server.R相同的目录中(我已经尝试将图像放在R的主目录中)。
我检查了输出的HTML,它看起来与成功显示存储在本地计算机上的图像的HTML文档中的HTML相同。事实上,如果我将输出HTML从闪亮的静态页面复制并保存,并将图像放在同一个目录中,然后在我的浏览器中打开它,图像就会显示出来。

I can't seem to get shiny to display an image in a table if the image is stored on my machine. I can get it to work if the image is specified by URL, but I do not know of any simple way to "serve" the image so that it can be found by URL as opposed to just using the image file name and putting the file in same directory as ui.R and server.R (I have tried putting the image in R's home directory as well). I have checked the HTML that is output and it appears to be just the same as that in HTML docs which succeed at displaying images stored on the local machine. In fact, if I copy and save the output HTML from shiny as a static page, with the image in the same dir, then open that in my browser, the image does display.

我正在使用的server.R和ui.R脚本粘贴在下面。

The server.R and ui.R scripts I am using are pasted below.

有没有人知道一个好的解决方案或其他解决方案?

Does anyone know of a good work-around or other solution?

感谢您的帮助。

server.R脚本:

The server.R script:

#server.R
require(shiny)
shinyServer(function(input, output){
    output$mytable <- renderTable({
        dat <- data.frame(
            country = c('USA', 'China','Working directory'),
            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>',
                             getwd())
        )
        dat
    }, sanitize.text.function = function(x) x)
})

ui.R脚本:

require(shiny)

shinyUI(
    tableOutput('mytable')
)


您的项目的URL机器就是这些东西,我可以用来在我的机器上显示R简介:

The URL to an item on your machine is just something along these lines, which I could use to bring up the "Introduction to R" on my machine:

 http://127.0.0.1:19812/doc/manual/R-intro.html

所以你需要确定放在 127.0.0.1:19812 之间的正确目录/路径和文件名(并检查您的端口号。)

So you need to determine the proper directory/path to place between 127.0.0.1:19812 and the file name (, and also check your port numbers.)