Edit data frame after upload with R Shiny


#1

...Good Morning / Good afternoon,
I currently trying to be able to upload a .csv/.txt file on the Shiny Web App. Then we would like to be able to choose the parameters (Time/Temperature/turbidity/….) and finally obtain a line graph based on the selected Input.
I am stuck at the intermediate step between the moment when the file is uploaded and data’s reading. The file need to be modified to obtain a new file, for that the program needs to:
-delete the seven first columns,
-delimit the different columns,
-Add a name to each column,
I don’t understand where I’ll have to implement my routine into the Server.R part

My data base file is here:

SAMBAT Martot Ti C/T/D/Tbd/Do GPS : 50067
V:0,Pression,m
V:1,Température,°C
V:2,Conductivité,mS
V:3,Turbidité,NTU
V:4,Oxygène saturation,%
V:5,Tension batterie,V
150118065024 0.350 7.348 0.344 19.006 104.470 10.663
150118070523 0.348 7.348 0.345 19.141 105.070 10.760
150118072023 0.346 7.348 0.346 18.013 105.090 10.788
150118073523 0.342 7.351 0.346 17.561 105.030 10.767
150118075023 0.342 7.351 0.347 17.019 105.110 10.804
150118080523 0.335 7.352 0.348 16.478 105.190 10.818
150118082023 0.335 7.354 0.348 16.613 105.070 10.825
150118083523 0.331 7.355 0.349 15.936 105.310 10.777
150118085023 0.330 7.356 0.349 16.117 105.230 10.813

I would like to obtain this type of data base:

"SambatTime";"Pression";"Temperature";"Conductivite";"Turbidite";"Oxygene";"Batterie"
2018-01-15 06:50:24;0.35;7.348;0.344;19.006;104.47;10.663
2018-01-15 07:05:23;0.348;7.348;0.345;19.141;105.07;10.76
2018-01-15 07:20:23;0.346;7.348;0.346;18.013;105.09;10.788
2018-01-15 07:35:23;0.342;7.351;0.346;17.561;105.03;10.767
2018-01-15 07:50:23;0.342;7.351;0.347;17.019;105.11;10.804
2018-01-15 08:05:23;0.335;7.352;0.348;16.478;105.19;10.818
2018-01-15 08:20:23;0.335;7.354;0.348;16.613;105.07;10.825
2018-01-15 08:35:23;0.331;7.355;0.349;15.936;105.31;10.777
2018-01-15 08:50:23;0.33;7.356;0.349;16.117;105.23;10.813
2018-01-15 09:05:23;0.324;7.357;0.349;16.162;105.22;10.824

There is my code :
library(shiny); library(ggplot2); library(reshape2); library (lubridate)

ui = fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("inputFile", "Browse for file"), #Upload button
#After file is uploaded, read the columns in the server function,
# and create a responsive dropdown menu for plotting the variables
uiOutput("plot.params") #Responsive x and y dropdown menu
),
mainPanel(
tabsetPanel(
tabPanel("graph",plotOutput("plot")),
tabPanel("table", tableOutput("contents"))
)
)
)
)

server = function(input, output, session) {

#Read in the uploaded data file and create a reactive variable called data_set
data_set <- reactive({
  
inFile<- input$inputFile
  if(is.null(input$inputFile)) 
    return(NULL)
  read.csv(input$inputFile$datapath, header = TRUE, sep=";",skip=7)
})

#Create a (reactive) dropdown menu for selecting X and Y
output$plot.params <- renderUI({ list(
  fluidRow(selectInput(inputId = "xaxisGrp", label = "X", choices = names(data_set() )) ),
  fluidRow(selectInput(inputId = "yaxisGrp", label = "Y", choices = names(data_set() )) )
)})
output$contents <- renderTable({
  if(is.null(input$inputFile)) 
    return(NULL)
  read.csv(input$inputFile$datapath, header = TRUE, sep=";",skip=7)
})

#Create a plot- copied from OP with minor edit to ggplot()
output$plot = renderPlot(
  {
    df <- data_set()
    gp <- NULL
    if (!is.null(df)){
      xv <- input$xaxisGrp  #from the reactive ui selecInput
      yv <- input$yaxisGrp  #from the reactive ui selecInput
      if (!is.null(xv) & !is.null(yv)){
        if (sum(xv %in% names(df))>0){ # supress error when changing files
          mdf <- melt(df,id.vars=xv,measure.vars=yv)
          gp <- ggplot(data=mdf, aes_string(x=xv,y="value",color="variable")) + 
            geom_point()+  #aes() moved from here into ggplot()
            geom_smooth(method="lm")
        }
      }
    }
    return(gp)
  })
output$contents <- renderTable({
  if(is.null(input$inputFile)) 
    return(NULL)
  read.csv(input$inputFile$datapath, header = TRUE, sep=";")
})

}

shinyApp(ui,server)

The code used to convert the data file in R :
library(lubridate)

FileData<-read.table("sambat_mesures_50067_150118065024.txt",header=FALSE, sep=" ", dec=".",skip=7, fill=FALSE, colClasses = "character")
ifelse(exists("Stage"),
Stage<-rbind(Stage,FileData),
Stage<-FileData)

SambatTime<-dmy_hms(Stage[,1])
Pression<- as.numeric (Stage[,2])
Temperature<-as.numeric (Stage[,3])
Conductivite<-as.numeric (Stage[,4])
Turbidite<-as.numeric (Stage[,5])
Oxygene<-as.numeric (Stage[,6])
Batterie<-as.numeric (Stage[,7])

file_to_read <- data.frame(SambatTime,Pression,Temperature,Conductivite,Turbidite,Oxygene,Batterie, check.rows=T)

Thanx in advance for your answers,
KoogJack