为什么在尝试使用 rstanarm 包部署应用程序时 Shiny 会出错

如何解决为什么在尝试使用 rstanarm 包部署应用程序时 Shiny 会出错

长期以来一直在 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。
  • 从源代码而不是编译版本安装 rstanarmrstan
  • 编写一个非常简单的新应用,包括 rstanarmrstanarm,但在使用 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)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res