【问题标题】:Shiny SelectInput to generate filepath for renderImage闪亮的 SelectInput 为 renderImage 生成文件路径
【发布时间】:2017-02-08 18:58:28
【问题描述】:

我的脚本的 www 文件夹中有一系列“.jpg”文件。我想让 renderImage 根据我的 UI 的输入(日期、平台)使用名为“dateplatform.jpg”的文件名来渲染图像。当我在 server.r 文件中尝试以下脚本时,应用程序未显示任何图像。有什么想法吗?

ui(部分)

       fluidRow(
                column(width=12,
                imageOutput("platformimage")
                      )
               )

服务器(部分)

    filename <- reactive ({
    paste(input$date, input$platform, sep="")
    })

    output$platformimage <- reactive({
    renderImage({
    list(src = filename(),
         width = 600,
         height = 600)

            },deleteFile = FALSE)
    })

【问题讨论】:

  • renderImage 不需要嵌入到 reactive
  • @HubertL 我将其添加为反应式,因为我收到“警告:file.info 中的错误:无效的文件名参数”日期的默认选择,平台不包含图像。

标签: r shiny reactive


【解决方案1】:

filename 必须至少附加扩展名,normalizePath 可能更安全:

filename <- reactive({
    normalizePath(file.path(paste0(input$date, input$platform '.jpg')))
})

如果失败,可能是因为服务器找不到文件。检查filename()创建的路径,并在file.path()内部修复

希望这会有所帮助。

【讨论】:

  • @G Gamba,我确实仍然看到一个问题。如果我手动将 src 添加到直接文件路径,它会生成一个很好的图像,它是在尝试让它粘贴输入的名称以表示 renderImage 有问题的日期和平台。我确实将它作为服务器中的 renderImage 和 UI 中的 imageOutput。对吗?
  • 尝试将 output$path &lt;- renderText({filename()}) 放在 server.R 中,将 textOutput('path') 放在 UI 中。结果是什么?另外,从renderImage中取出reactive
猜你喜欢
  • 2017-09-10
  • 1970-01-01
  • 1970-01-01
  • 2019-01-24
  • 2015-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-29
相关资源
最近更新 更多