Flexdashboard slow when opening SQLite connection on global chunk

I want to create a flexdashboard that will show data from a large (5Gb) SQLite database. I placed JUST the DBI::dbConnect on the global chunk in order to establish the connection for all other parts in the code but I'm not retrieving any data at this step. With this, the dashboard takes 30 second to start. If I remove the DBI::dbConnect from the global chunk, the dashboard starts in a couple of seconds.

Connecting to the database in R Console, with con <- DBI::dbConnect(RSQLite::SQLite(), dbname = 'my_large_db.sqlite) also takes less than a second.

Why is it so slow when doing it in flexdashboard global chunk? Any suggestions on how to speed things up? In the future, I plan on moving the data to a PostgreSQL server. But for now I'm using SQLite.

Thanks

PS - Just found out that it does not matter if the DBI::dbConnect call is inside the global chunk or any other chunk. Whenever I try to open the connection, flexdashboard takes 30 seconds to load.

I tested with a smaller SQLite database (23 Mb) and the dashboard loaded very fast. So am I right to assume that if I just open a connection with a database in Shiny, without pulling any data from the DB, the shiny app will somehow scan the database so, a large DB will take a long time?

Also just tested with a postgreSQL database. Dashboard starts very fast. So SQLite seems to be the culprit here.

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