[英]R Shiny - Can't Display Prerendered Image
I have a prerendered image in the images folder of the Shiny app folder. 我在Shiny app文件夹的images文件夹中有一个预渲染的图像。 I'm trying to get the app to render the image EXG.jpeg, but only the alt text shows up.
我正在尝试使该应用程序呈现图像EXG.jpeg,但仅显示alt文本。 What's going wrong?
怎么了
\\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 File \\ 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')
)
)
))
You weren't using the correct imageOutput
label. 您没有使用正确的
imageOutput
标签。 img1
is wrong, you needed plot
because that is how the output
list entry is named. img1
是错误的,您需要plot
因为这是output
列表条目的命名方式。 So this works: 所以这工作:
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)
I added a deleteFile=FALSE
at the end to keep renderImage
from deleting it every time it ran. 我在最后添加了
deleteFile=FALSE
,以防止renderImage
每次运行时都将其删除。 Not sure why it wants to do this by default. 不知道为什么默认要这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.