Reputation: 155
I have a prerendered image in the images folder of the Shiny app folder. I'm trying to get the app to render the image EXG.jpeg, but only the alt text shows up. 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
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')
)
)
))
Upvotes: 1
Views: 989
Reputation: 22847
You weren't using the correct imageOutput
label. img1
is wrong, you needed plot
because that is how the output
list entry is named. 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. Not sure why it wants to do this by default.
Upvotes: 2