问题描述
长期以来一直在 Shiny 服务器站点上的 Shiny 应用程序中使用 rstanarm 包,并使用我编写的许多应用程序。最近,Shiny 在尝试上传使用 rstanarm 的新应用程序时出现错误。如果我不使用 rstanarm 就没有问题。带有 rstanarm 的 Shiny 应用程序在本地运行良好,只是无法构建到 Shiny。下面是代码和部署日志的结尾:
BEGINNING OF CODE
library(shiny)
library(shinyWidgets)
library(rstanarm)
library(readxl)
library(tidyverse)
ui <- fluidPage(
titlePanel("Check AV22"),sidebarLayout(
sidebarPanel(
fileInput('path','Choose file to upload',accept = c(
'application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.ms-excel.sheet.macroEnabled.12'
)
),),mainPanel(
plotOutput("Plot")
)
)
)
server <- function(input,output) {
df <- eventReactive(input$path,{
inFile <- input$path
if(is.null(inFile))
return(NULL)
read_excel("./grbg.xlsx",sheet=2,skip=3)
})
prior <- reactive({
prior <- read.csv("./coefficients.csv")[20,]
})
stan_data <- reactive({
list(N=nrow(df()),x=df()$conc,y=df()$ds,mnint=prior()$mean_intercept,sdint=prior()$sd_intercept,mnslope=prior()$mean_slope,sdslope=prior()$sd_slope)
})
post <- reactive({
as.matrix(stan_glm(ds~conc,data=df(),family="binomial",prior_intercept=normal(prior()$mean_intercept,prior()$sd_intercept,autoscale=TRUE),prior=normal(prior()$mean_slope,prior()$sd_slope,autoscale=TRUE)))
})
q <- reactive({
pred <- matrix(rep(NA,4000*1000),nrow=4000)
x <- seq(0,max(df()$conc),length=1000)
for(i in 1:1000) {
pred[,i] <- 1 / (1 + exp(-(post()[,1] + post()[,2]*x[i])))
}
pred_quantiles <- t(apply(pred,2,function(x) quantile(x,c(.1,.5,.8))))
pred_quantiles <- data.frame(x,pred_quantiles)
names(pred_quantiles) <- c("x","q1","q5","q8")
pd90 <- (log(0.9/0.1) - post()[,1])/post()[,2]
pd90_quantiles <- quantile(pd90,c(0.1,0.5,0.8))
list(pred_quantiles=pred_quantiles,pd90_quantiles=pd90_quantiles)
})
output$Plot <- renderPlot({
ggplot() + geom_point(data=df(),aes(x=conc,y=ds),shape=4,col="black",size=2) +
geom_line(data=q()$pred_quantiles,aes(x=x,y=q1),col="slategray3",size=1) +
geom_line(data=q()$pred_quantiles,y=q5),col="mediumblue",y=q8),col="violet",size=1) +
geom_vline(xintercept=q()$pd90_quantiles[2],linetype="dashed") +
theme_classic()
})
}
shinyApp(ui = ui,server = server)
ENDING OF CODE
FINAL PART OF DEPLOYMENT LOG SHOWING ERROR
Eigen::Product<Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double,double>,const
Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>,const
Eigen::Matrix<double,1,-1> >,const Eigen::Transpose<Eigen::Matrix<double,-1,1> > >,Eigen::Matrix<double,-1>,0>; Rhs = Eigen::Matrix<double,1>]’
/opt/R/4.0.4/lib/R/library/RcppEigen/include
################################# End Task Log #################################
Error: Unhandled Exception: Child Task 905587151 Failed: Error building image:
Error building rstanarm (2.21.1). Build exited with non-zero status: 1
Execution halted
当工作中的 IT 团队使用最新的 Microsoft 补丁更新我的 Windows 10 计算机时,问题就开始了。这可能是巧合,我所知道的是,到目前为止,我能够使用 rstanarm 将应用程序部署到 Shiny 服务器。我还在一台非工作计算机上使用 R、RStudio、rtools
和所有相关软件包的最新下载进行了尝试,但我得到了同样的错误。但这并不排除它是 Windows 的东西,因为非工作计算机也有所有最新的 Windows 更新。
版本:Windows 10、R 4.0.5、RStudio 1.4.1106、rstanarm 2.21.1、rstan 2.21.2、shiny 1.6.0、shinyWidgets 0.6.0、rtools 4.0、Rcpp 1.0.6、Rcpp3.3.3 .1,rsconnect 0.8.17。
到目前为止我尝试过的:
- 在 2021 年 4 月上旬之前从未安装过 R/RStudio 的 Windows 10 计算机上安装所有最新版本。
- 在部署到 Shiny 时回滚到早期的 R 版本在
rstanarm
中运行良好,例如 4.0.3(我认为)和 3.6.3。 - 从源代码而不是编译版本安装
rstanarm
和rstan
。 - 编写一个非常简单的新应用,包括
rstanarm
和rstanarm
,但在使用rstan
时出现相同的错误。
另一件刚刚开始的奇怪事情 - 当我从 Shiny 应用程序中调用它时,{{1}} 使 r 会话崩溃,甚至在本地运行。 Rstan 在 RStudio 脚本中运行时不会使 R 崩溃,但在 Shiny 应用程序中运行时会使其崩溃。与 rstanarm 不同,带有 Rstan 的应用程序将构建到 Shiny 服务器,但随后 Shiny 服务器上的 rstan 应用程序在运行时出错,可能是因为它使 R 崩溃。
如果我在错误的地方发布了这个,请原谅我,并将我重定向到正确的地方来发布这样的问题。
谢谢。
解决方法
我一开始写这个是为了评论,但太多了。关于这个问题,我一直在经历我能想到的任何事情。如果没有您的数据,我无法运行该文件,以查看是否遇到相同的错误。出于好奇,您是否查看过 rstanarm
包及其依赖项的上次更新时间?你知道这个应用程序什么时候有效吗?它在 12 月有效,但现在不行吗?那种东西。
要查看依赖项,请使用 tools::package_dependencies("rstanarm")
我查看了设备上软件包的更新,其中有几个是最近更新的。如果我们能把它缩小到一个包问题,那么解决问题就会容易很多。
如果您想查看依赖项和软件包上次更新的日期,请使用以下命令:
library(tidyverse) # for dplyr
library(lubridate) # for as_date()
pk <- package_dependencies("rstanarm") %>% unlist()
data.frame("Packages" = pk,"Date_updated" = lapply(pk,packageDate) %>%
unlist() %>%
as_date()
) # end data.frame
# 1 Rcpp 2021-01-14
# 2 methods 2020-10-11
# 3 bayesplot 2021-01-07
# 4 ggplot2 2020-12-17
# 5 lme4 2020-11-30
# 6 loo 2020-12-07
# 7 Matrix 2019-11-25
# 8 nlme 2020-08-21
# 9 rstan 2020-07-07
# 10 rstantools 2020-07-05
# 11 shinystan 2018-04-29
# 12 stats 2020-10-11
# 13 survival 2020-09-24
# 14 RcppParallel 2021-02-24
# 15 utils 2020-10-11
# 16 StanHeaders 2020-12-16
# 17 BH 2020-12-12
# 18 RcppEigen 2020-12-17
或者,您可以通过这种方式查看设备上的内容,但它只显示版本,而不显示日期。
ps <- packageStatus()
data.frame(Package = ps$inst$Package,V = ps$inst$Version,stat = ps$inst$Status) %>%
filter(Package %in% pk) %>%
left_join(ps$avail[1:2])
这是我的设备所在的位置。包中的更改或 Excel 的更新可能是问题所在。尽管我确实花时间浏览了您使用过的功能以及它们如何与任何更新相关联,但我没有任何反应。
# Package V stat Version
# 1 bayesplot 1.8.0 ok 1.8.0
# 2 BH 1.75.0-0 ok 1.75.0-0
# 3 ggplot2 3.3.3 ok 3.3.3
# 4 lme4 1.1-26 ok 1.1-26
# 5 loo 2.4.1 ok 2.4.1
# 6 Matrix 1.2-18 upgrade 1.3-2
# 7 methods 4.0.3 ok <NA>
# 8 nlme 3.1-149 upgrade 3.1-152
# 9 Rcpp 1.0.6 ok 1.0.6
# 10 RcppEigen 0.3.3.9.1 ok 0.3.3.9.1
# 11 RcppParallel 5.0.3 upgrade 5.1.1
# 12 rstan 2.21.1 upgrade 2.21.2
# 13 rstantools 2.1.1 ok 2.1.1
# 14 shinystan 2.5.0 ok 2.5.0
# 15 StanHeaders 2.21.0-7 ok 2.21.0-7
# 16 stats 4.0.3 ok <NA>
# 17 survival 3.2-7 upgrade 3.2-10
# 18 utils 4.0.3 ok <NA>
我会继续回来查看,看看您是否在此处提供了更多信息。如果不出意外,如果数据不是专有的,则数据或数据的最小可重复示例 - excel 电子表格以及您已对其进行设置也会使帮助更容易一些。>
,LPA,
这很奇怪,因为即使只是使用默认的 Shiny 示例并包括库 rstanarm,我也遇到了同样的错误。我已经在多台运行 Windows 10 且具有最新 R 和 RStudio 更新的计算机上进行了尝试。代码在本地有效,但无法发布。
虽然这绝对不是答案,但我希望其他人或许能够使用以下简单代码来帮助排除故障。
library(shiny)
library(rstanarm)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins","Number of bins:",min = 1,max = 50,value = 30)
),# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input,output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[,2]
bins <- seq(min(x),max(x),length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x,breaks = bins,col = 'darkgray',border = 'white')
})
}
# Run the application
shinyApp(ui = ui,server = server)