如何解决*** 发现段错误 ***;地址 0x5573328516d8,导致通过 Shinyapps.io 部署的 R Shinygolem应用程序中的“内存未映射” 模块
我的 R Shiny 应用程序出现问题,该应用程序在本地运行良好,但在通过 Shinyapps.io 部署时不规则地返回“与服务器断开连接:重新加载”。 请注意用户不会在每次点击“创建/更新图表!”按钮时断开连接,而是(奇怪的是)只是不定期地断开连接。
作为参考,以下是我关注的记录消息:
2021-07-13T12:24:26.495243+00:00 shinyapps[4159264]: *** caught segfault ***
2021-07-13T12:24:26.495244+00:00 shinyapps[4159264]: address 0x5573328516d8,cause 'memory not mapped'
后跟以以下开头的回溯:
2021-07-13T12:24:26.497790+00:00 shinyapps[4159264]: 1: policy %in% input$recycling_option_choice_checkBox
并以:
2021-07-13T12:24:56.324135+00:00 shinyapps[4159264]: 91: local({ if (identical(.Platform$OS.type,"unix")) { whoami <- system("whoami",intern = TRUE) if (identical(whoami,"root")) { stop("Attempted to run application as whoami=",whoami,"; USER=",Sys.getenv("USER")) } } ...
2021-07-13T12:24:56.324136+00:00 shinyapps[4159264]: An irrecoverable exception occurred. R is aborting Now ...
由于该应用程序是在 golem 框架中构建的,因此我无法提供最小/可重现的示例。以下代码行旨在让您了解模块的结构。另请注意,用户仅在单击模块中的“创建/更新图!”按钮时才会不时断开连接,其中使用 checkBoxGroupinput() 对用于后续绘图的数据进行子集化。对于使用 selectinput() 而不是 checkBoxGroupinput() 的其他模块,该应用不仅可以在本地运行,还可以在 Shinyapps.io-server 上运行。
模块
用户界面
mod_plotting_ui <- function(id){
ns <- NS(id)
# InfoBox showing by a text and a color whether graph has to be created for the first time (blue),is up to date (green) or has to be updated (red)
shinydashboard::infoBoxOutput(ns("informationBox1"),width = 12)
# Action button for the graph
actionButton(ns("go"),"Create/update graph!",icon = icon("arrow-down"))
# checkBoxGroupInput (with bsButton for additional info on specific options)
sidebarPanel(
tags$style(HTML('#bsButton_recycling_option_choice_checkBox {margin-top: 30px}')),fluidRow(
column(10,tags$div(
checkBoxGroupInput(ns("recycling_option_choice_checkBox"),"Choose recycling options:",c("Option 1" = "Option 1","Option 2" = "Option 2"
"Option 3" = "Option 3","Option 4" = "Option 4","Option 5" = "Option 5"),selected = c("Option 1"))
)
),column(2,shinyBS::bsButton(ns("bsButton_recycling_option_choice_checkBox"))
)
)
)
# Description belonging to the prevIoUs bsButton
shinyBS::bsPopover(id = ns("bsButton_recycling_option_choice_checkBox"),title = HTML(paste("<strong>Description</strong>")),content = HTML("..."),placement = "right",trigger = "focus",options = list(container = "body"))
}
服务器
mod_plotting_server <- function(input,output,session,type,parent){
ns <- session$ns
# Initiate the status
status <- shiny::reactiveVal()
# Initially (empty/grey) graph
r <- shiny::reactiveVal(
plot = ggplot(dataframe)
)
# Status after clicking the actionButton (i.e. after creating a graph for the first time or after updating a graph)
out <- eventReactive( input$go,{
status("Well done. Graph is up to date!")
paste("")
})
# Subsetting and plotting
observeEvent( input$go,{
# Subsetting
dataframe_subset<- dataframe %>%
dplyr::filter(
policy %in% input$recycling_option_choice_checkBox # this seems to be the source of the problem
)
# Plotting
r$plot <- ggplot(data = dataframe_subset,...)
})
# Status at beginning and status when graph needs to be updated
observeEvent({list(input$recycling_option_choice_checkBox)},ifelse(getCount(input$go) == 0,#1) getCount(): function returning number of clicks on actionButton (see below)
{status("Create first graph by clicking the 'Create/update graph!'-Button!")},{status("Please update the graph according to your changed inputs by clicking the 'Create/update graph!'-Button!")})
)
# Maximum and minimum options that can be chosen in checkBox
observe({
# Max 3
if(length(input$recycling_option_choice_checkBox) > 3) {
showNotification("You cannot choose more than 3 recycling options at a time.",duration = 8,type = "message",closeButton = FALSE)
}
# Min 1
if(getCount(input$go) >= 1 & length(input$recycling_option_choice_checkBox) < 1) {
showNotification("You need to choose at least one recycling option.",closeButton = FALSE)
}
})
# Reaction if maximum or minimum is reached
observe({
if(length(input$recycling_option_choice_checkBox) > 3){
updateCheckBoxGroupInput(session,"recycling_option_choice_checkBox",selected = tail(input$recycling_option_choice_checkBox,3))
}
if(length(input$recycling_option_choice_checkBox) < 1){
updateCheckBoxGroupInput(session,selected = "Option 1")
}
})
# Actual information Box showing by a text and a color whether graph has to be created for the first time (blue),is up to date (green) or has to be updated (red)
output$informationBox1 <- shinydashboard::renderInfoBox({
shinydashboard::infoBox(
title = "",value = tags$div(style = "line-height: 1.4;",tags$h5(renderText({out()}),renderText({status()}))),icon = icon("exclamation-circle"),color = getColor(status(),input$go),#2) getColor(): function returning a specific color (see below)
fill = TRUE
)
})
# Show graph
output$plot <- renderPlot({
r$plot
})
}
模块外定义的函数
# 1)
getColor <- function(placeholder,counts) {
place <- placeholder
count <- 0 + counts
if(count == 0)
{return('light-blue')}
else if(count != 0 & place == "Well done. Graph is up to date!")
{return('olive')}
else return('red')
}
# 2)
getCount <- function(counts) {
count <- 0 + counts
if(count == 0)
{return(0)}
else return("more than 0")
}
任何帮助表示赞赏!提前致谢!
最大
解决方法
这意味着您正在使用的至少一个库中存在(相当严重的)错误。如果这不是 Windows,您可以尝试使用 valgrind 运行它(在终端中使用 List<ObjectCountDTO> dtoList = countsMap.entrySet().stream()
.map(e -> new ObjectCountDTO(e.getKey(),e.getValue()).collect(Collectors.toList());
dtoList.add(new ObjectCountDTO("ALL",countsMap.values().stream().mapToLong(i->i).sum()));
之类的内容进行初始化,然后从那里运行闪亮的应用程序) - 这应该会告诉您哪个特定的包导致了崩溃。也许如果您检查完整的错误日志,它会说明具体失败的地方。
之后,您应该将错误报告给包维护人员。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。