How to handle data source issues in shiny app

I am experiencing an issue with one of the data sources my shiny dashboard app pulls from. In this app I currently have 2 data sources:

  • csv files that are on a server - I use curl and read.csv to import
  • a MySQL database where I use pool and RMySQL

The csv files are actually created each day by a chron job that does lots of complex querying for data. Today, however, there was an issue with one of the scripts and 1 of the csv files contains no data - this issue causes the dashboard to crash as several lines of code are expecting data and variables where none exist.

This got me wondering if there is something already native to r/shiny that could handle an issue like this in the future.

I already use shiny::validate to check for issues when rendering plots, but that only affects the plotOutput and not the underlying data manipulation. I have used try/catch blocks in java when I was in school but have never implemented something like that in R.

Also, another use case I would like to handle would be if the database cannot be connected to for some reason.

My research is not turning anything else up, any suggestions?

try/catch is possible in R too, but there are multiple alternatives. There is an overview of packages that do this type of thing here:

What you probably want can be broadly described as input validation. Usually this means argument checking, but in fact you can think of data checking in the same framework. My colleague, for example, created a package that takes exactly this idea:

2 Likes