如何实现 renderImage 函数

How to implement renderImage function

我无法通过 shiny 网页中的子目录路径上传图片。

  1. 我创建了一个名为 "www" 的子目录文件夹并放置了图像。
  2. 我也试过使用URL。

还是不行

imageOutput("d", width = 300, height = 500)

output$d <- renderImage({ 
                        list(src= "driveaxle.png",
                        filetype = "image/png",
    )}), deletefile = False}

我试过你的代码。它需要修改几个区域。 首先,您需要在 www 文件夹下创建一个名为 images 的文件夹。您还需要从单独的变量中获取文件名。

我试过了,它看起来像: UI.R

fluidPage(
  sidebarLayout(
    sidebarPanel(
      "This is Sidebar"
    ),
    mainPanel(imageOutput("d", width = 300, height = 500)
              )
  )
)

Server.R

function(input, output) {
  output$d <- renderImage({ 
    filename <- normalizePath(file.path('./www/images','studio logo.jpg'))

    list(src = filename,
         contentType = 'image/png',
         alt = "This is alternate text")
  }, deleteFile = FALSE)


  }

输出如下:

您可以在这里阅读:https://shiny.rstudio.com/articles/images.html