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

时间:2016-03-15 18:04:05

标签: r shiny shiny-server

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

\ Server File

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')
  )




  )

))

1 个答案:

答案 0 :(得分:2)

您没有使用正确的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) 

产量: enter image description here

更新

我在最后添加了deleteFile=FALSE,以防止renderImage每次运行时都将其删除。不知道为什么它默认要这样做。