首页 > 解决方案 > 在 Shiny 中直接访问 Webshot 图像

问题描述

目标:创建网站的屏幕截图,当用户输入基因名称时自动显示,例如 TP53、NAPRT

问题:虽然这在本地有效,但当我在线发布时它失败了。我怀疑这是因为从 webshot 下载的文件不再可访问。我试图用 www/Filename.png 指定文件名,但这既适用于所有基因,也适用于在线仅适用于那些之前已经创建的基因,因此图片已经存在于 www

如您所见,运行它 R 有效,但发布它没有。

library(webshot)

# Define UI for application that draws a histogram
ui <- fluidPage(
  textInput("gene", "Gene symbol", value = "TP53"),
  imageOutput('myImage')
)

# Define server logic required to draw a histogram
server <- function(input, output) {
  output$myImage <- renderImage({
   outfile <- paste(input$gene,'.png', sep="") 

    owd <- setwd(tempdir())
    webshot(paste('http://ualcan.path.uab.edu/cgi-bin/Pan-cancer.pl?genenam',input$gene,sep="="),
            outfile,
            selector = '#banner3',
            delay = 2,
            expand = c(0,40,0,0))
    # Return a list containing the filename
    list(src = outfile,
         contentType = 'image/png',
         width = 600,
         height = 450,
         alt = "This is alternate text")
  }, deleteFile = FALSE)
    }

# Run the application 
shinyApp(ui = ui, server = server)```

标签: rshiny

解决方案


推荐阅读