RODBC查询导致服务器关闭

RODBC查询导致服务器关闭,r,odbc,rodbc,shiny,R,Odbc,Rodbc,Shiny,我们正在Redhat6.7上运行一个闪亮的服务器(和闪亮的仪表板),并且在尝试使用RODBC查询数据库时遇到了SEGFULT。当我们将文件源代码导入app.R或向server.R文件中的数据库发出查询请求时,就会发生这种情况。当我们在R控制台中运行相同的代码时,它工作得很好 看起来在Shiny和RODBC之间一定有某种类型的交互作用导致了这个问题。作为一种解决方法,我们使用RJDBC,它工作得很好,但我们担心它不能很好地为我们扩展。而且相当慢 有人知道我们能做些什么使RODBC正常工作吗 下面是

我们正在Redhat6.7上运行一个闪亮的服务器(和闪亮的仪表板),并且在尝试使用RODBC查询数据库时遇到了SEGFULT。当我们将文件源代码导入app.R或向server.R文件中的数据库发出查询请求时,就会发生这种情况。当我们在R控制台中运行相同的代码时,它工作得很好

看起来在Shiny和RODBC之间一定有某种类型的交互作用导致了这个问题。作为一种解决方法,我们使用RJDBC,它工作得很好,但我们担心它不能很好地为我们扩展。而且相当慢

有人知道我们能做些什么使RODBC正常工作吗

下面是我们正在运行的生成错误的代码:

library(RODBC)
myConn <- odbcConnect("DSN_Name")
segment <- sqlQuery(myConn, "SELECT * FROM foo")
An error has occurred

The application exited unexpectedly.

socket hang up

Listening on http://127.0.0.1:37079 Attaching package: ‘shinydashboard’

The following object is masked from ‘package:graphics’: box

Loading required package: ggplot2

Attaching package: ‘plotly’ The following object is masked from ‘package:ggplot2’: last_plot

The following object is masked from ‘package:graphics’: layout Attaching package: ‘DT’

The following objects are masked from ‘package:shiny’: dataTableOutput, renderDataTable

Loading required package: DBI Loading required package: rJava Loading required package:

NLP Attaching package: ‘NLP’ The following object is masked from ‘package:ggplot2’: annotate

Loading required package: RColorBrewer

*** caught segfault ***
address (nil), cause 'unknown'

Traceback:
1: .Call(C_RODBCDriverConnect, as.character(connection), id, as.integer(believeNRows), as.logical(readOnlyOptimize))
2: odbcDriverConnect("DSN=DB_Name")
3: eval(expr, envir, enclos)
4: eval(expr, p)
5: eval.parent(Call)
6: odbcConnect("DB_Name")
7: eval(expr, envir, enclos)
8: eval(ei, envir)
9: withVisible(eval(ei, envir))
10: source("RODBC.R")
11: eval(expr, envir, enclos)
12: eval(ei, envir)
13: withVisible(eval(ei, envir))
14: source(file, ..., keep.source = TRUE, encoding = checkEncoding(file))
15: sourceUTF8(fullpath, local = new.env(parent = globalenv()))
16: func(fname, ...)
17: appObj()
18: handler(req)
19: handler(req)
20: handler(...)
21: handlers$invoke(req)
22: handler(req)
23: func(req)
24: doTryCatch(return(expr), name, parentenv, handler)
25: tryCatchOne(expr, names, parentenv, handlers[[1L]])
26: tryCatchList(expr, classes, parentenv, handlers)
27: tryCatch(expr, error = function(e) { call <- conditionCall(e) if (!is.null(call)) { if (identical(call[[1L]], quote(doTryCatch))) call <- sys.call(-4L) dcall <- deparse(call)[1L] prefix <- paste("Error in", dcall, ": ") LONG <- 75L msg <- conditionMessage(e) sm <- strsplit(msg, "\n")[[1L]] w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w") if (is.na(w)) w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], type = "b") if (w > LONG) prefix <- paste0(prefix, "\n ") } else prefix <- "Error : " msg <- paste0(prefix, conditionMessage(e), "\n") .Internal(seterrmessage(msg[1L])) if (!silent && identical(getOption("show.error.messages"), TRUE)) { cat(msg, file = stderr()) .Internal(printDeferredWarnings()) } invisible(structure(msg, class = "try-error", condition = e))})
28: try({ inputStream <- if (is.null(data)) nullInputStream else InputStream$new(data, dataLength) req$rook.input <- inputStream req$rook.errors <- ErrorStream$new() req$httpuv.version <- packageVersion("httpuv") if (!is.null(req$HTTP_CONTENT_TYPE)) req$CONTENT_TYPE <- req$HTTP_CONTENT_TYPE if (!is.null(req$HTTP_CONTENT_LENGTH)) req$CONTENT_LENGTH <- req$HTTP_CONTENT_LENGTH resp <- func(req) if (is.null(resp) || length(resp) == 0) return(NULL) resp$headers <- lapply(resp$headers, paste) if ("file" %in% names(resp$body)) { filename <- resp$body[["file"]] owned <- FALSE if ("owned" %in% names(resp$body)) owned <- as.logical(resp$body$owned) resp$body <- NULL resp$bodyFile <- filename resp$bodyFileOwned <- owned } resp})
29: rookCall(.app$call, req, req$.bodyData, seek(req$.bodyData))
30: (function (req) { on.exit({ if (!is.null(req$.bodyData)) { close(req$.bodyData) } req$.bodyData <- NULL }) rookCall(.app$call, req, req$.bodyData, seek(req$.bodyData))})(<environment>)
31: eval(substitute(expr), envir, enclos)
32: evalq((function (req) { on.exit({ if (!is.null(req$.bodyData)) { close(req$.bodyData) } req$.bodyData <- NULL }) rookCall(.app$call, req, req$.bodyData, seek(req$.bodyData))})(<environment>), <environment>)
33: doTryCatch(return(expr), name, parentenv, handler)
34: tryCatchOne(expr, names, parentenv, handlers[[1L]])
35: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
36: doTryCatch(return(expr), name, parentenv, handler)
37: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), names[nh], parentenv, handlers[[nh]])
38: tryCatchList(expr, classes, parentenv, handlers)
39: tryCatch(evalq((function (req) { on.exit({ if (!is.null(req$.bodyData)) { close(req$.bodyData) } req$.bodyData <- NULL }) rookCall(.app$call, req, req$.bodyData, seek(req$.bodyData))})(<environment>), <environment>), error = function (x) x, interrupt = function (x) x)
40: .Call("httpuv_run", PACKAGE = "httpuv", timeoutMillis)
41: run(timeoutMs)
42: service(timeout)
43: serviceApp()
44: withCallingHandlers(expr, error = function(e) { handle <- getOption("shiny.error") if (is.function(handle)) handle()})
45: shinyCallingHandlers(while (!.globals$stopped) { serviceApp() Sys.sleep(0.001)})
46: runApp(Sys.getenv("SHINY_APP"), port = port, launch.browser = FALSE) aborting ...
server.R

library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
titlePanel("Hello Shiny!"),
# Sidebar with a slider input for the 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")
)
  )
    ))
library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
# Expression that generates a histogram. The expression is
# wrapped in a call to renderPlot to indicate that:
#
#  1) It is "reactive" and therefore should re-execute automatically
#     when inputs change
#  2) Its output type is a plot
output$distPlot <- renderPlot({
x    <- faithful[, 2]  # Old Faithful Geyser data
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')
})
  })
库(闪亮)
#定义绘制直方图所需的服务器逻辑
shinyServer(功能(输入、输出){
#生成直方图的表达式。该表达式为
#包装在对renderPlot的调用中,以指示:
#
#1)它是“反应性”的,因此应自动重新执行
#当输入发生变化时
#2)其输出类型为绘图

输出$distPlot首先,我要感谢RStudio的Joe Cheng。他帮了我很大的忙,真的尽力帮我解决了这个问题。非常感谢

因此,我遇到的问题是(IMHO)糟糕的代码结构造成的。以下是我犯的错误,一旦它们被修复,事情就会按预期进行

  • 错误1-我正在调用服务器.R文件app.R。这是一个错误 过时的命名约定,不应使用
  • 错误2-错误 我的server.R文件的最后一行称为函数shinyApp(ui, 这导致我的odbc驱动程序出现重大问题 数据库。它正在创建一个非常大的堆栈,我的客户将在其中 被压得太深,导致seg故障。故事的寓意, 使用server函数结束server.R文件
我的闪亮服务器现在正在愉快地运行!:)

谢谢乔的帮助


这是完整的线程-

你能用纯文本格式化错误,使其可读吗?我重新格式化了错误,使其更可读。你的意思是:1.将
app.R
拆分到
server.R
ui.R
?2.关闭数据库连接以解决问题?谢谢。