I have a Shiny
web application that I am allowing users to upload their files in to. I am performing a couple lines of data manipulation to make it easier to plot on my Dygraph
output.
In my code, I need to remove the Time column that is uploaded with each file (each file has a Time column), and then replace it with a time column that I saved as a .csv
file (called time
).
I receive the error that Error: replacement has 3001 rows, data has 2990
. How do should I resolve this problem? My time column is specially formatted in Excel to work with the Dygraph
output, which is why I replace all uploaded time columns with this (called time
) loaded in my workspace.
uploadedData <- reactive({
# input$file1 will be NULL initially. After the user selects
# and uploads a file, it will be a data frame with 'name',
# 'size', 'type', and 'datapath' columns. The 'datapath'
# column will contain the local filenames where the data can
# be found.
inFile <- input$file1
if (is.null(inFile))
return(NULL)
uploadedFile <- read.csv(inFile$datapath, header=input$header, sep=input$sep,
quote=input$quote)
uploadedFile[1]<- NULL
uploadedFile$Time <- time
uploadedFile$Time <- as.POSIXct(strptime(uploadedFile$Time,"%m/%d/%Y %H:%M:%S" ))
uploadedFile <- xts(uploadedFile[,-1], order.by=uploadedFile[,1])
})
output$graph <- renderDygraph({
uploadedFile <- uploadedData()
updateSelectizeInput(session, 'uploadChannels', choices = names(uploadedFile))
fileInput <- input$uploadChannesl
component5 <- uploadedFile[, fileInput]
dygraph(component5, main = "Temperature Rise Data Plot") %>%
dyAxis("y", label = "Temp (F)") %>%
dyAxis("x", label = "Time (min)")%>%
dyRangeSelector() %>%
dyOptions(colors = RColorBrewer::brewer.pal(8, "Dark2"))
})
Revision - I revised the items inside of xts, but whenever I choose a channel, it always reverts back to the Scan channel. If I choose "Watts" the wattage chart briefly pops up until it quickly reverts back to the Scan chart.
output$graph <- renderDygraph({
uploadedFile <- input$file1
if (is.null(uploadedFile))
return(NULL)
uploadedFile <- read.csv(uploadedFile$datapath, header=input$header, sep=input$sep,
quote=input$quote)
uploadedFile$Time <- as.POSIXct(strptime(uploadedFile$Time,"%H:%M:%S"))
uploadedFile$ctime <- strptime(paste(uploadedFile$Time), "%Y-%m-%d %H:%M:%S")
updateSelectizeInput(session, 'uploadChannels', choices = names(uploadedFile))
fileInput <- input$uploadChannels
component5 <- uploadedFile[, fileInput]
xts(component5, uploadedFile$Time) %>%
dygraph()
})
})
ui.R
shinyUI(fluidPage(
navbarPage("Engineering Laboratory Data",
tabPanel("Upload your Own File:",
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
tags$hr(),
checkboxInput('header', 'Header', TRUE),
radioButtons('sep', 'Separator',
c(Comma=',',
Semicolon=';',
Tab='\t'),
','),
radioButtons('quote', 'Quote',
c(None='',
'Double Quote'='"',
'Single Quote'="'"),
'"'),
selectInput("uploadChannels", label = "Choose a Channel",
choices = NULL)
),
mainPanel(
dygraphOutput('graph')
))
))))