R Shiny SQLite App中的对象对象错误

object Object error in R Shiny SQLite App

我正在尝试使用 SQLite 数据库开发 R Shiny 应用程序。但是我在从数据库中获取任何数据时遇到了这个错误。错误信息是:

Loading required package: shiny
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
    filter, lag
The following objects are masked from ‘package:base’:
    intersect, setdiff, setequal, union**

在应用内,它显示:

[object Object]

谁能帮帮我?您对开发SQLite数据库有什么建议吗?

代码如下:

# Libraries
library(stats)
library(shiny)
library(RSQLite)
library(dtplyr)
library(dplyr)
library(DBI)

# Globar Variables 
db <- dbConnect (SQLite(),
                  "/Users/sudiptobosu/200922/20200714PPCP.sqlite")

# Global Function
names_ppcp = dbGetQuery(db, "SELECT ALL PPCP FROM mydata")

#server
shinyServer(function (input, output, session) {
  dplyr::filter
  stats::filter
  
  output$ppcpOut <- reactive({
    input$user1
  })  

  output$propertyOut <- reactive({
    input$user2
  })

  ppcpquery <- reactive({
    input$user1
  })

  queryy <- reactive({
    gsub("<ppc>", ppcpquery(), "SELECT Solubility FROM mydata WHERE PPCP = '<ppc>'")
  })

  output$valueout <- reactive({
    dbGetQuery(db, queryy())
  })

  #propertyquery <- eventReactive ({input$user2})  

  session$onSessionEnded (function() {
    dbDisconnect(db)
  })
})

#ui
ui <- fluidPage ( 
  titlePanel("bo-DEREC CE"),
  sidebarLayout( 
    sidebarPanel(
      selectInput("user1","Select the PPCP",choices = names_ppcp),
      selectInput("user2","Select the property",choices = c("Solubility","Volatility","Adsorbability","Degradability"))
    ),
    mainPanel(
      textOutput("ppcpOut"),
      textOutput("propertyOut"),
      textOutput("valueout")
    )
  )
)

不应在 textOutputtableOutput 的用户界面上呈现数据帧。然后将反应性调用调整为 renderTable。通常 input$ 个对象应该包裹在 reactive 中。另外,考虑适当的参数化,例如 DBI:sqlInterpolate:

服务器调整

...

# INPUTS
ppcpquery <- reactive({
  input$user1
})

propertyquery <- reactive({
  input$user2
})

# OUTPUTS
output$ppcpOut <- renderText({
    ppcpquery()
})  

output$propertyOut <- renderText({
    propertyquery()
})

output$valueOut <- renderTable({
  # PREPARED STATEMENT WITH PLACEHOLDER
  sql <- "SELECT Solubility FROM mydata WHERE PPCP = ?ppc")

  # BIND PARAMETER
  query <- DBI::sqlInterpolate(db, sql, ppc = ppcpquery())

  # RUN QUERY AND RETURN RESULTS
  dbGetQuery(db, query)
})

ui 调整

...

mainPanel(
  textOutput("ppcpOut"),         # ALIGNS TO renderText
  textOutput("propertyOut"),     # ALIGNS TO renderText
  tableOutput("valueOut")        # ALIGNS TO renderTable
)

现在,如果dbGetQuery returns一个one-row和one-column数据框,那么你可以在server和[中使用renderTexttextOutputui 中。但从列中提取值:

dbGetQuery(db, query)$Solubility[[1]]