I built a shiny app which takes a CSV file uploaded by the user and adds headers to it and a couple of new columns, in order to do some calculation afterwards.
The uploaded CSV file consists in 2 columns like this:
1 0.21
1 0.20
1 0.23
2 0.40
2 0.42
2 ...
To upload the file I use this code (which is working):
data1<- reactive({
inFile <- input$file1
if(is.null(inFile)){return()}
data1<- read.csv(file=inFile$datapath,header =input$header,sep=input$sep)
})
Next step would be add the headers to this two columns and add two more columns in this way:
Dose Response SquareRoot Log
1 0.21 sq(Response) log(Response)
1 0.20 ... ...
1 0.23 ... ...
2 0.40 ... ...
2 0.42 ... ...
2 ...
In an R session the code I would use is this:
data1<- read.csv(file=inFile$datapath,header =input$header,sep=input$sep)
colnames(data1) <-c("Dose","Response")
data1$ResponseLog <- log10(data1$Response + 1)
data1$ResponseSqRoot <- sqrt(data1$Response + 1)
If I do this in shiny adding these lines into my Rshiny app it won't work and give me the error:
ERROR:argument of length 0 even if I just define the column names using colnames()
.
So my question is, is there a way to edit the dataframe I just uploaded? I this question has already been asked could you redirect me there because I couldn't find the solution. I hope I gave you enough details to understand the problem.