使本地文件显示在闪亮的数据表中

时间:2019-06-10 18:57:55

标签: r shiny

我正在使用以下代码尝试在数据表中显示图像。我看不到本地图像,主要是因为我显然不了解带有光泽的路径。

library(shiny)
library(DT)
library(shinydashboard)
library(here)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(DT::dataTableOutput("test")),
  dashboardBody()
)

server <- shinyServer(function(input, output, session) {
  dat <- data.frame(
    country = c('China', 'Belgium'),
    flag = c('<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>',
             '<img src="/www/EndoMinerLogo.png" height="52"></img>'
    )
  )
  output$test <- DT::renderDataTable({ DT::datatable(dat, escape = F) })
})

shinyApp(ui=ui, server=server)

我的闪亮应用程序文件与www文件夹位于同一文件夹中。 (并且我已经尝试了/ www并没有使用“ /”

我怎么了?

1 个答案:

答案 0 :(得分:0)

问题非常接近Rstudio shiny not finding image in www folder

但是,我经常遇到一个陷阱。 另外,请确保工作目录匹配。 如果您通过控制台而不是通过runApp()运行应用程序,则工作目录可能与包含闪亮应用程序的文件夹(和www文件夹)不同。

因此,您可能希望通过runApp()启动应用程序,因为这样会自动设置工作目录(或手动设置工作目录)。

给出正确的工作目录,确保正确引用www文件夹中的文件。按照链接的“问题/答案”中的说明,删除路径中的“ www”,或使用addResourcePath()作为注释中已经提到的@StéphaneLaurent,将文件放在www文件夹之外。