rshiny

Variance in a CSV file after uploading it in Shiny


I have made a fileInput which loads the .CSV file[dataset] directly after user has chosen it.

data <- data.frame(A=c(2.076,3.99,4.95,5.99,6.578,7.6.7),B=c(3.000,7.980,8.0001,9.001,2.000,1.056,2.789,3.546),C=c(1,1,1,2,2,1,1,1,1,2,2))

In ui.r

library(shiny)
library(ggplot2)
shinyUI(fluidPage(
    fileInput('file', 'Choose CSV file',
            accept=c('csv', 'comma-separated-values','.csv')),
    ))

Problem : I am not getting variance values

 In server.r
  library(shiny)
 library(ggplot2)

shinyServer(function(input, output,session) {

    d<-reactive({
            if (is.null(input$file))
                    return(NULL)                
            d<-read.csv(input$file$datapath)
            d <- transform(data, D= A+B, E= A-B) 
            d <- transform(data, var1 =var(D), var2= var(E))
             d
             # In table I am getting variance value as 0.00 
             })

Solution

  • You can use

     data <- transform(data, D= A+B, E= A-B)