我正在尝试使用以下 Shiny 网站提供的示例代码片段将本地图像文件渲染到 Shiny 应用程序界面:
ui <- fluidPage(
imageOutput("plot3")
)
server <- function(input, output, session) {
# Send a pre-rendered image, and don't delete the image after sending it
# NOTE: For this example to work, it would require files in a subdirectory
# named images/
output$plot3 <- renderImage({
filename <- normalizePath(file.path('./images',
paste('image', '2', '.jpeg', sep='')))
# Return a list containing the filename
list(src = filename, alt = "Alternate text")
}, deleteFile = FALSE)
}
shinyApp(ui, server)
当我运行应用程序时它不起作用。但是,当我添加回interactive()最初在示例代码中的函数时,将主代码体包含在内,我能够毫无问题地显示本地图像文件。
if (interactive()) {
ui <- fluidPage(
imageOutput("plot3")
)
server <- function(input, output, session) {...
}
这让我感到困惑,因为 Shiny 的许多教程和演示都表明可以在不将代码体封装在范围内的情况下完成渲染。
有没有人遇到过类似的情况?将本地图像文件渲染到 Shiny 应用程序中?