R ggplot2错误“结果必须是所有原子或所有数据帧”
我的闪亮应用程序出现了不一致的错误,我似乎无法找出问题所在。这是最常见的错误R ggplot2错误“结果必须是所有原子或所有数据帧”,r,ggplot2,shiny,R,Ggplot2,Shiny,我的闪亮应用程序出现了不一致的错误,我似乎无法找出问题所在。这是最常见的错误 Error: Results must be all atomic, or all data frames. 闪亮的应用程序基本上允许用户选择一个或多个文件,然后读取具有不同列数的文件,使用rbind.fill plyr将它们合并,然后熔化,再合并到ggplot2。ggplot2使用镶嵌面将一个绘制在另一个的下方 运行Win 8、R 3.2.0、plyr_1.8.2 ggplot2_1.0.1、shiny_0.12.
Error: Results must be all atomic, or all data frames.
闪亮的应用程序基本上允许用户选择一个或多个文件,然后读取具有不同列数的文件,使用rbind.fill plyr将它们合并,然后熔化,再合并到ggplot2。ggplot2使用镶嵌面将一个绘制在另一个的下方
运行Win 8、R 3.2.0、plyr_1.8.2 ggplot2_1.0.1、shiny_0.12.0的计算机和运行Ubuntu 14.04、R 3.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)
})
这似乎是plyr的一个问题,它可能会在下一次R更新中得到修复。在此之前,您可以按照以下步骤进行修复: 安装特定于平台的开发工具: Windows:从下载并安装Rtools33.exe 基于Ubuntu或Debian的Linux:sudo apt get install r-base-devel 基于Rpm的Linux:安装r-devel Mac:从安装Xcode命令行工具 安装devtools 安装.packagesdevtools 编译并安装plyr的固定版本 devtools::安装\u githubhadley/plyr 重新启动R/Rstudio
感谢您努力提供所有这些链接,但是不可能提供一个简单的可复制的内联示例吗?对我们来说,这样做会容易得多。。我想我可以,但是代码太多了,而且可能会很长。如果我将代码最小化太多,错误就不可再现。这就是我的意思,试着找出错误发生的代码块以及导致错误的最小代码是什么。。。如果你不能,那么这很好,只是想让它更容易帮助FYI,应用程序似乎可以正常工作使用plyr_1.8.1或plyr 1.8.2.9000的开发版本,而不是plyr_1.8.2。谢谢你的努力。这是我很长一段时间以来取得的最大突破。我升级到了plyr的最新github版本。不幸的是,我现在得到了这个新的错误,它似乎也源于打印时的ggplot fn。.Callloop_apply中出错,as.integern,f,env:loop_apply未从当前命名空间plyr解析