我的闪闪发亮的应用程序出现了不一致的错误,我似乎找不出出了什么问题。这是最常见的错误。
Error: Results must be all atomic, or all data frames.这个闪亮的应用程序基本上允许用户选择一个或多个文件,然后读取这些文件(列数不同),使用rbind.fill() (plyr)合并这些文件,然后将它们合并到melt(),然后到ggplot2。ggplot2使用面法绘制一个下面的图。
运行Win 8、R3.2.0、plyr_1.8.2 ggplot2_1.0.1、shiny_0.12.0和运行Ubuntu14.04、R3.2.0、shiny_0.12.0、plyr_1.8.2、ggplot2_1.0.1的服务器上的错误是相同的。
代码在下面。
#ui.R
shinyUI(fluidPage(
titlePanel("Error test App"),
sidebarLayout(
sidebarPanel(
selectInput("data", label = "Select files",
choices = c("file1.txt","file2.txt", "file3.txt","file4.txt","file5.txt"),
selected=NULL,
multiple=T)
),
# Show a plot of the generated distribution
mainPanel(
imageOutput("plotoutput",width="100%",height="100%")
)
)
))
#server.R
library(ggplot2)
library(plyr)
options(shiny.trace=TRUE)
#plotfunction
#reads selected files and transforms them into a dataframe compatible to be read by ggplot and the plot is returned
plotfunction <- function(files = NULL, na.rm = TRUE)
{
#loop to process selected files
plist <- vector("list",length=length(files))
for (i in 1:length(files))
{
df1 <- read.delim(file = files[i],header=F,stringsAsFactors=F)
k <- ncol(df1)
df1$Ind <- factor(1:nrow(df1))
df1$Num <- factor(rep(i, nrow(df1)))
plist[[i]] <- df1
}
#MOST LIKELY ERROR BLOCK ====================================================
#combine list to one dataframe
df2 <- plyr::rbind.fill(plist)
#melt
df3 <- reshape2::melt(df2, id.var = c("Ind", "Num"))
#ggplot
p <- ggplot2::ggplot(data = df3, aes(x = Ind, y = value, fill = variable))+
geom_bar(width = 1, space = 0, stat = "identity", position = "stack", na.rm = na.rm)+
scale_x_discrete(expand = c(0, 0))+
scale_y_continuous(expand = c(0, 0))+
facet_grid(Num~.)+
labs(x = NULL, y = NULL)+
theme(legend.position = "none", panel.grid = element_blank(), panel.background = element_blank(),
axis.ticks = element_blank(), axis.text = element_blank(), axis.line = element_blank(),
axis.title = element_blank(),
plot.margin = grid::unit(c(0.1, 0, 0, 0), "lines"),
strip.text=element_blank())
#MOST LIKELY ERROR BLOCK ====================================================
return(p)
}
#shinyserver
shinyServer(function(input, output) {
#renderimage
output$plotoutput <- renderImage({
fnvalidate <- function(input) {if(is.null(input)) print("Select one or more files.")}
validate(fnvalidate(input=input$data))
sp1 <- plotfunction(files=input$data)
png("plot.png", height=2, width=6, res=200, units="cm")
print(sp1)
dev.off()
return(list(src = "plot.png",
contentType = "image/png",
width = round((6*200)/2.54, 0),
height = round((1*length(input$data)*200)/2.54, 0),
alt = "plot"))
},deleteFile=T)
})发布于 2015-06-11 20:55:40
这似乎是plyr的一个问题,它可能会在下一次R更新中得到修复。在此之前,您可以按照以下步骤修复它:
https://stackoverflow.com/questions/30688041
复制相似问题