Your error message, in a shiny app, usually means you are trying to perform an operation you'd usually perform on a data frame on a function (that is, a closure).
I suspect this error is popping up on the line with x <- mydataset[,2] , perhaps after you've loaded that gets returned NULL where mydataset is set up...