3
这几乎是同样的问题在这里提出: dynamically add plots to web page using shiny动态显示图像中闪亮的UI
但不是产生可变次数的曲线(这我已经成功地完成),我想将选择的图像上传到应用程序并将其显示在用户界面上。使用上述问题中所述的相同方法,我使用下面的代码生成了我的应用程序。但只有第一个图像在UI中呈现。
今天我错过了什么明显的事情?
- [R 3.2.2(视窗7) 光泽0.12.2
server.R
library(shiny)
shinyServer(function(input, output) {
output$files <- renderTable(input$files)
files <- reactive({
files <- input$files
files$datapath <- gsub("\\\\", "/", files$datapath)
files
})
output$images <- renderUI({
image_output_list <-
lapply(seq_along(nrow(files())),
function(i)
{
imagename = paste0("image", i)
imageOutput(imagename)
})
do.call(tagList, image_output_list)
})
observe({
for (i in seq_along(nrow(files())))
{
local({
my_i <- i
imagename = paste0("image", my_i)
output[[imagename]] <-
renderImage({
list(src = files()$datapath[my_i],
alt = "Image failed to render")
}, deleteFile = FALSE)
})
}
})
})
ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel("Uploading Files"),
sidebarLayout(
sidebarPanel(
fileInput(inputId = 'files',
label = 'Select an Image',
multiple = TRUE,
accept=c('image/png', 'image/jpeg'))
),
mainPanel(
tableOutput('files'),
uiOutput('images')
)
)
))
辉煌。我现在看到它。非常感谢您的时间。 – Benjamin
很高兴能帮到你! –