0

I am trying to build a shiny application, with the first Drop down menu populated from a SQLite using renderUI.

Below is my 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)
})

Here is my 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"),

           )
           )
    )

))

here is the dropdown of origins

I get

Error in sqliteSendQuery(con, statement, bind.data) : 
  expired SQLiteConnection

Not sure where I am going wrong. Please help

satishvad
  • 11
  • 6

1 Answers1

0

I'm guessing the dbDisconnect(db) at the end of the code is there to disconnect from the db at the end of the app. You should use session$onSessionEnded for that.

http://shiny.rstudio.com/reference/shiny/latest/session.html

How to implement a cleanup routine in R Shiny?

Timing events when session ends

Community
  • 1
  • 1
user5029763
  • 1,903
  • 1
  • 15
  • 23