R Shiny - 无法显示预渲染图像

R Shiny - Can't Display Prerendered Image

我在 Shiny 应用程序文件夹的图像文件夹中有一个预渲染图像。我试图让应用程序呈现图像 EXG.jpeg,但只显示替代文本。出了什么问题?

\服务器文件

setwd('C:/Users/E0265074/Documents/PrelimShiny/')

  function(input, output) {output$Option1 = renderUI({

  if (input$study == 'EX') {

    selectInput('differ', label='Patient ID', choices = c('013412-826-001-002','013412-840-001-001','013412-840-001-002','013412-840-001-003','013412-840-001-004'))

  }

})

output$plot <- renderImage({
      return(list(
        src = "./images/EXG.jpeg",
        contentType = "image/jpeg",
        alt = "Face"
      ))
    })

})

\UI 文件

library(shiny) 


shinyUI(fluidPage(

  titlePanel('Biomarker Comparison'),

  sidebarLayout(sidebarPanel(

    tabsetPanel(type = c('tabs'), 

                tabPanel('Plot 1 Options', selectInput('study', label = 'Study Type', choices = c('EX')), 
                         uiOutput('Option1'), 
                         uiOutput('Option2'), 
                         uiOutput('Option3')

                ),

                tabPanel('Plot 2 Options', selectInput('studya', label = 'Study Type', choices = c('EX')), 
                         uiOutput('Option1a'), 
                         uiOutput('Option2a'), 
                         uiOutput('Option3a')
                )

    ), 

  ),


  mainPanel(imageOutput('img1')
  )




  )

))

您没有使用正确的 imageOutput 标签。 img1 是错误的,您需要 plot 因为那是 output 列表条目的命名方式。所以这有效:

library(shiny)

u <- shinyUI(fluidPage(
  titlePanel('Biomarker Comparison'),
  sidebarLayout(sidebarPanel(
    tabsetPanel(type = c('tabs'), 
                
                tabPanel('Plot 1 Options', selectInput('study', label = 'Study Type', 
                                                                  choices = c('EX')), 
                         uiOutput('Option1'), 
                         uiOutput('Option2'), 
                         uiOutput('Option3')
                ),
                tabPanel('Plot 2 Options', selectInput('studya', label = 'Study Type', 
                                                                choices = c('EX')), 
                         uiOutput('Option1a'), 
                         uiOutput('Option2a'), 
                         uiOutput('Option3a')
                )
    )
  ),
    mainPanel(imageOutput('plot')
  )
  )
))
s <- function(input, output) {
  
  output$Option1 = renderUI({
    if (input$study == 'EX') {
      
      selectInput('differ', label='Patient ID', 
                  choices = c('013412-826-001-002','013412-840-001-001',
                              '013412-840-001-002',
                              '013412-840-001-003','013412-840-001-004'))
    }
  })
  output$plot <- renderImage({
    return(list(
      src = "./images/EXG.jpeg",
      contentType = "image/jpeg",
      alt = "Face"
    ))
  }, deleteFile = FALSE)
}
shinyApp(ui = u, server = s) 

产量:

更新:

我在末尾添加了一个 deleteFile=FALSE 以防止 renderImage 每次 运行 都删除它。不确定为什么要默认这样做。