我正在尝试构建一个闪亮的应用程序,第一个使用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
不确定我哪里出错了。请帮忙
答案 0 :(得分:0)
我猜测代码末尾的dbDisconnect(db)
是否会在应用程序结束时与数据库断开连接。您应该使用session$onSessionEnded
。
http://shiny.rstudio.com/reference/shiny/latest/session.html