【问题标题】:How to put entire image location in tags$img of shiny package?如何将整个图像位置放在闪亮包的 tags$img 中?
【发布时间】:2019-06-14 20:45:42
【问题描述】:

tags$img 的代码如下:

  • 工作中...当图像存储在“www”文件夹和 src = "Rlogo.png"
  • 不工作...当给出图像的整个路径时

我需要将整个位置放在我的一个闪亮的应用程序中,app.R 文件将从命令提示符运行。请帮忙谢谢..

library(shiny)

ui <- fluidPage(
  box(
    tags$img(height = 100, width = 100,src = "Rlogo.png"),
    tags$img(height = 100, width = 100,src = "E:/myApp/www/Rlogo.png")
  )
)

server <- function(input, output, session) {

}

shinyApp(ui, server)

【问题讨论】:

  • 这样想:您是否真的想在发布网站时将整个本地硬盘的内容暴露给全世界?我对此表示怀疑。因此,您基本上无法从硬盘驱动器上的任意位置提供内容。它们需要位于您的 Web 服务器应用程序列入白名单的商定位置 - 在您的示例中为 www 文件夹。
  • @KonradRudolph 是的。我明白你的意思了。那么,你知道任何解决方案,app.R 文件将从 cmd 提示符运行并出现图像。
  • 有一个替代解决方案.. stackoverflow.com/questions/54145275/…
  • 不使用renderImage的替代方案:Link

标签: r shiny


【解决方案1】:

使用imageOutput 代替tags$img

library(shiny)

ui <- fluidPage(
    box(
        tags$img(height = 100, width = 100,src = "Rlogo.png"),
        imageOutput('image')
    )
)

server <- function(input, output, session) {
    output$image <- renderImage({
            list(src = "E:/myApp/www/Rlogo.png",
                 alt = "This is alternate text"
            )
        }, deleteFile = TRUE)
}

shinyApp(ui, server)

【讨论】:

    猜你喜欢
    • 2014-01-01
    • 2016-03-26
    • 2019-11-15
    • 1970-01-01
    • 2021-01-22
    • 2018-01-06
    • 2014-12-26
    • 1970-01-01
    • 2016-12-12
    相关资源
    最近更新 更多