Formatting reactive data.frames in Shiny

I am responding to my own question largely to say that I was being a nincompoop. Once the file is read in using reactiveFileReader() it becomes a “reactive source”. As explained in the shiny tutorial here the reactive sources are modified from outside – a user entering a new value, or in this case, an update of the file. You can’t modify it from inside the server.r.

So, for my case I used the col.names and colClasses options in read.csv() to get the original data in the best format that I could. I also made use of the very useful setAs function to get read.csv to understand how to format the date, as explained here: Specify date format for colClasses argument … .

From there, any new columns that I needed to create from the data had to be done as a separate object using a reactive function like this:

NewThing<-reactive({ function(MyReacitveCSVdata()$colname) })

And then NewThing() in turn can be used however you wish. This is how you can get around issues such as character values in an otherwise numeric column. If you try to just bring it in using colClasses="numeric" you will get an error and the read.csv() will fail. Instead first import the column as “character” and then use reactive({}) with as.numeric() to assign it to a new object. Be sure to note that the new object cannot be a new column in the data.frame you brought in using reactiveFileReader(), instead it must be a new object that depends on that data.frame.

Leave a Comment