0

我的 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.",
                       duration = 8, type = "message", 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, "recycling_option_choice_checkbox", 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")
}

任何帮助表示赞赏!提前致谢!

麦克斯

4

1 回答 1

1

这意味着您正在使用的至少一个库中存在(相当严重的)错误。如果这不是 Windows,您可以尝试使用 valgrind 运行它(valgrind R在终端中初始化并从那里运行闪亮的应用程序) - 这应该告诉您哪个特定包导致崩溃。也许如果您检查完整的错误日志,它会说明它具体在哪里失败。

之后,您应该将错误报告给包管理员。

于 2021-07-16T02:50:44.673 回答