Shiny app can't access SQLite db on RStudio Connect Server: “database is locked”

I've deployed an R Shiny app on a R Studio Connect Server and I'm simply trying to get data from a SQLite database which I've included in the deployed application.

When I run the app locally (through the runApp function), everything works fine and the data is fetched from the database.

When I run the app from the R Studio Connect Server, I have the following error message: "Warning: Error in : database is locked" I do not understand why the db is locked or how to unlock it.

The tree of the deployed application looks like this

- app.R
- data/
|-- database.db

The code of my shiny app is as follows:

library(dplyr)
library(shiny)
library(RSQLite)

loadData <- function() {
    path_to_db <- "data/database.db"
    # Connect to the database
    db <- dbConnect(SQLite(), path_to_db)
    # Construct the fetching query
    isin_static_info_tb = "isin_static_info_table"
    query <- sprintf("SELECT * FROM %s", isin_static_info_tb)
    # Submit the fetch query and disconnect
    data <- dbGetQuery(db, query)
    dbDisconnect(db)
    data
}

# Define UI for application that draws a histogram
ui <- fluidPage(

    actionButton(inputId = "displayTable", label = "Show table"),
    
    tags$hr(),
    
    tableOutput(outputId = "table")
    
)

# Define server logic required to draw a histogram
server <- function(input, output) {
    
    data <- eventReactive(input$displayTable, {
        return(loadData())
    })
    
    output$table <- renderTable(data())
}

# Run the application 
shinyApp(ui = ui, server = server)

As it was hinted to me on StackOverflow, I checked for permissions on the database file with with the function file.access("data/minitool.db", mode = 0/1/2/4). It returned 0 (so success) for mode 0/2/4, as it does when I run my app locally (before deployment), so I would say the permissions are ok...

maybe a miscommunication but why check a minitool.db when you have a database.db ?

Yes my bad, I copy/paste my code quickly and didn't adjust for the database name (minitool being the real name of the database in my app that I simplified when describing my case)

I only skim read this Connecting to a locked database, message that looks like an error · Issue #197 · r-dbi/RSQLite (github.com)
but perhaps dbConnect(synchronous = NULL) option is worth trying

Thanks for your answer. Yes, I've checked this thread already, but dbConnect(synchronous = NULL) does not change the end result, it only gets rid off following warning : "Warning: Couldn't set synchronous mode: database is locked".

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.