As a general rule, this common error indicates you have attempted to treat a dataset variable which is a function as if it were an index-able data type such as data frame. This R user error frequently occurs when you are building web applications using the shiny application R package/framework using the reactive () R function.
For those not familiar with functional programming, a closure refers to a function (created at run-time) that can be passed around like a variable. This programming approach can significantly simplify code development and data analysis in the R programming language.
For R shiny app development, this error frequently occurs after you have created objects such as a data frame, list, and character vector using the reactive() R function. It is tempting to attempt to treat the R object after this point as if it were an ordinary index-able data type, using brackets to reference specific elements of the data object. Which will result in the server error message in question: “object of type closure is not subsettable.”
For R shiny app development, remember you need to use brackets when referencing an R object created using the reactive () function. Something like this base R code example for instance:
If you get this error output during other types of R code development, double check your variable names to make sure you’re not mixing variable names. Along the same lines, avoid naming variables the same (or similar) names as the functions contained within the base R library to reduce the risk of creating an “Object of type closure is not subsettable” problem via a typo.
Error: object of type ‘closure’ is not subsettable