【发布时间】:2019-10-27 02:18:15
【问题描述】:
我想创建一个闪亮的应用程序,让用户能够浏览和加载图像,然后显示它。我的问题是闪亮是否支持这一点。
#ui.r
pageWithSidebar(
headerPanel('Image Recognition'),
sidebarPanel(
fileInput("file1", "Choose Image",
accept = c(
".jpg")
))
,
mainPanel(
imageOutput("file1")
)
)
#server.r
library(shiny)
function(input, output, session) {
(shiny.maxRequestSize=30*1024^2)
output$myImage <- renderImage({
# A temp file to save the output.
# This file will be removed later by renderImage
file1 <- tempfile(fileext = '.png')
# Generate the PNG
png(file1, width = 400, height = 300)
dev.off()
# Return a list containing the filename
list(src = file1,
contentType = 'image/png',
width = 400,
height = 300,
alt = "This is alternate text")
}, deleteFile = TRUE)
}
【问题讨论】:
-
当心所选文件的路径:它通常来自一个格式错误的文件路径,它来自一个非工作块;)此外,当您调用
png()时没有定义outfile但是只有file1 -
我使用 (shiny.maxRequestSize=30*1024^2) 作为尺寸,但它不起作用。我也改变了outfile
-
请问回溯日志呢?
-
shiny.maxRequestSize是您需要设置的选项,而不是您需要创建的变量。删除该行并将options(shiny.maxRequestSize = 30*1024^2)放在 server.R 文件中的library(shiny)调用之后。 -
编辑问题以删除文件大小特定的错误/问题是有意义的。但也许这样的事情已经回答了另一个问题:community.rstudio.com/t/…