sqliteSendQuery(con, statement, bind.data) 错误:SQLiteConnection 过期
Error in sqliteSendQuery(con, statement, bind.data) : expired SQLiteConnection
我正在尝试构建一个闪亮的应用程序,第一个下拉菜单使用 renderUI 从 SQLite 填充。
下面是我的server.r
library("shiny")
library("RSQLite")
shinyServer(function(input, output) {
db<-dbConnect(SQLite(),"PNL.sqlite")
origins<-data.frame(dbGetQuery(db,"SELECT Origin_Name from CNS_Origin_List"))
output$origin<-renderUI({
selectInput(inputId = "origin",label = "Select Origin",choices = origins$Origin_Name)
})
query<-reactive({
sql<-dbGetQuery(db,paste0('SELECT Region_Name from CNS_Origin_List Where Origin_Name ="',input$origin,'"'))
})
#This is where the error occurs when I call the query()
output$region<-renderTable(query())
dbDisconnect(db)
})
这是我的ui.R
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
titlePanel("PNL Calculator!"),
# Sidebar with a slider input for the number of bins
fluidRow(
column(4,
wellPanel(
uiOutput(outputId = "origin"))),
column(6,
wellPanel(
tableOutput(outputId = "region"),
)
)
)
))
我明白了
Error in sqliteSendQuery(con, statement, bind.data) :
expired SQLiteConnection
不确定我哪里出错了。请帮助
我猜代码末尾的 dbDisconnect(db)
是为了与应用程序末尾的数据库断开连接。您应该为此使用 session$onSessionEnded
。
http://shiny.rstudio.com/reference/shiny/latest/session.html
How to implement a cleanup routine in R Shiny?
Timing events when session ends
我正在尝试构建一个闪亮的应用程序,第一个下拉菜单使用 renderUI 从 SQLite 填充。
下面是我的server.r
library("shiny")
library("RSQLite")
shinyServer(function(input, output) {
db<-dbConnect(SQLite(),"PNL.sqlite")
origins<-data.frame(dbGetQuery(db,"SELECT Origin_Name from CNS_Origin_List"))
output$origin<-renderUI({
selectInput(inputId = "origin",label = "Select Origin",choices = origins$Origin_Name)
})
query<-reactive({
sql<-dbGetQuery(db,paste0('SELECT Region_Name from CNS_Origin_List Where Origin_Name ="',input$origin,'"'))
})
#This is where the error occurs when I call the query()
output$region<-renderTable(query())
dbDisconnect(db)
})
这是我的ui.R
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
titlePanel("PNL Calculator!"),
# Sidebar with a slider input for the number of bins
fluidRow(
column(4,
wellPanel(
uiOutput(outputId = "origin"))),
column(6,
wellPanel(
tableOutput(outputId = "region"),
)
)
)
))
我明白了
Error in sqliteSendQuery(con, statement, bind.data) :
expired SQLiteConnection
不确定我哪里出错了。请帮助
我猜代码末尾的 dbDisconnect(db)
是为了与应用程序末尾的数据库断开连接。您应该为此使用 session$onSessionEnded
。
http://shiny.rstudio.com/reference/shiny/latest/session.html
How to implement a cleanup routine in R Shiny?
Timing events when session ends