Have been using the rstanarm package in Shiny apps on the Shiny server site for a long time and with a number of apps I've written. Recently, Shiny gives an error when trying to upload a new app that uses rstanarm. No problems if I do not use rstanarm. The Shiny app with rstanarm runs fine locally, it just won't build to Shiny. Below is the code and the end of the deployment log:
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,aes(x=x,y=q5),col="mediumblue",size=1) +
geom_line(data=q()$pred_quantiles,aes(x=x,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, -1>, 0>; Rhs = Eigen::Matrix<double, -1, 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
The problem started when the IT group at work updated my Windows 10 computer with the latest Microsoft patches. That could be a coincidence, all I know is that I was able to deploy apps with rstanarm to the Shiny server up until this time. I've also tried it out on a non-work computer using the latest downloads of R, RStudio, rtools
and all the associated packages, and I get the same error. But that doesn't exclude it being a Windows thing because the non-work computer also has all the latest Windows updates.
Versions: 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, RcppEigen 0.3.3.9.1, rsconnect 0.8.17.
What I've tried so far:
- Install all the latest of everything on a Windows 10 computer that has never had R/RStudio as of early April 2021.
- Roll back to earlier R versions when deploying to Shiny was working fine with
rstanarm
such as 4.0.3 (I think) and definitely 3.6.3. - Install
rstanarm
andrstan
from source instead of the compiled versions. - Write a new, very simple app, both with and without
rstanarm
, and get the same error when usingrstanarm
.
One other weird thing that has also just started - rstan
crashes the r session when I call it from within a Shiny app, even running locally. Rstan does not crash R when run in an RStudio script, but it does crash it when run in a Shiny app. The app with Rstan will build to the Shiny server, unlike rstanarm, but then the rstan app on the Shiny server errors out when run, presumably because it crashes R.
Please forgive me if I've posted this in the wrong place, and redirect me to the proper place to post such a question.
Thank you.