Welcome to the community @Couth! In addition to the previous responses, here is another way to stack a selected number of images in a shiny UI.
Within the folder where the shiny app .R file is located, I saved 10 identical images (Posit logo) within a folder named www. The code below first gathers the image filepaths via list.files
, specifying the www folder. Then, within a renderUI
call in the server, if the number selected is greater than 0, an HTML text statement is generated for the number of images selected. The images are stacked by including a break tag (<br>) at the end of the HTML statement.
library(shiny)
# get filepaths for all images in the wwww folder
my_images = list.files('www', full.names = F, pattern = '.PNG')
ui <- fluidPage(
br(),
selectInput('number',
'Select the number of images to show',
choices = 0:length(my_images),
multiple = F
),
br(),
uiOutput('images')
)
server <- function(input, output, session) {
output$images = renderUI({
req(input$number)
# show image(s) if 1 or more is selected
if(input$number > 0) {
display_image = function(i) {
HTML(paste0('<img src = ', my_images[i], ' style="margin-top: 5px;"><br>'))
}
lapply(1:input$number, display_image)
}
})
}
shinyApp(ui, server)