2016-11-18 3 views
0

Im Folgenden ist der Code, den ich in rstudio und erhalte die folgende Störung laufen versuchen, könnte jemand meinen Fehler freundlich darauf hinweisen:ungültige Verbindungsfehler erhalten, während mit ROracle in r Verbindungs ​​

Warning: Error in .oci.GetQuery: invalid connection Stack trace (innermost first): 84: .oci.GetQuery 83: .local 82: dbGetQuery 81: dbGetQuery 80: getqdata [P:/EI_DBA_Engineering/ShinyR/EI/App5/apptest.r#51] 79: ggplotly [P:/EI_DBA_Engineering/ShinyR/EI/App5/apptest.r#56] 78: func 77: origRenderFunc 76: output$dynamicPlot 1: runApp Der Code unten versucht, Um eine Verbindung zur Datenbank herzustellen und Daten abzurufen, erhalte ich zum Verbindungszeitpunkt einen Fehler.

require(ggplot2) 
require(scales) 
require(reshape) 
require(ROracle) 
require(shiny) 
library(plotly) 
ui <- dashboardPage(
    skin="green", 
    dashboardHeader(title = "Real Time Dashboard for EI"), 
    dashboardSidebar(disable = TRUE), 
    dashboardBody(
    fluidRow(
     # A stati"c valueBox 
     #column(5,DT::dataTableOutput("text1")) 
    ), 
    box(
     title = "CPU UTILIZATION DAILY " 
     ,status = "primary" 
     ,solidHeader = TRUE 
     ,collapsible = TRUE 
     ,width = "800px" 
     ,plotlyOutput('dynamicPlot', height = "300px") 
    ) 
)) 
server <- function(input, output, session) { 
    sqlstmt1 <- reactive({ 
    sqlstmt1 <- paste0("select instance_name from v$instance") 
    print (sqlstmt1) 
    return(sqlstmt1) 
    }) 
    con <- reactive({ 
    drv <- dbDriver("Oracle") 
    on.exit(dbDisconnect(con)) 
    con <- dbConnect(drv, dbname = "abcd", username = "aaaaa", password = "bbbbbbb") 
    print (con) 
    return(con) 
    }) 
    getqdata <- function (con) { 
    print ("inside get\n") 
    #print (con()) 
    #print (sqlstmt1()) 
    cat("Refreshing....","\n") 
    mdat <- dbGetQuery(con,sqlstmt1()) 
    return(mdat) 
    } 
    output$dynamicPlot <- renderPlotly({ 
    p1 <- getqdata(con()) 
    stout <- t(p1()) 
    mdata <- melt(p1(), id.var = c("TTIME", "ENTITY_NAME")) 
    print (mdata) 
    invalidateLater(10000, session) 
    #p1 <- plot_ly(mdata, x = ~TTIME, y = ~value, type = 'scatter', mode = 'lines', color= ~ENTITY_NAME , fill = 'tozeroy') %>% 
    # layout(xaxis = list(title = 'Date',showticklabels = FALSE), 
     #  yaxis = list(title = 'CPU Percentage')) 
     #ggplotly(p1) 
    #invalidateLater(10000, session) 
     }) 
    } 
shinyApp(ui, server) 

Antwort

0

Ich löste das Problem, indem die on.exit herausnehmen (dbDisconnect (con))

Verwandte Themen