Formatting reactive data.frames in Shiny

后端 未结 1 1921
我在风中等你
我在风中等你 2020-11-28 13:00

I have a working shiny application, but I am changing it so that the input data is reactive - it will update when the underlying data updates. It worked fine when it just re

相关标签:
1条回答
  • 2020-11-28 13:49

    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.

    0 讨论(0)
提交回复
热议问题