R 动态图输出的时间对象有问题
我正在为一个闪亮的应用程序编写一个脚本,它允许我的用户上传他们自己的CSV文件(任何人上传的所有文件都类似于这里的示例数据集:)。闪亮的应用程序应该允许用户使用SelectInput选择其中一个标题,然后在动态图形输出中对其进行图形化。我遇到的问题是将时间对象转换为适当格式以创建动态图输出的正确方法 现在,我收到了错误信息:R 动态图输出的时间对象有问题,r,excel,csv,R,Excel,Csv,我正在为一个闪亮的应用程序编写一个脚本,它允许我的用户上传他们自己的CSV文件(任何人上传的所有文件都类似于这里的示例数据集:)。闪亮的应用程序应该允许用户使用SelectInput选择其中一个标题,然后在动态图形输出中对其进行图形化。我遇到的问题是将时间对象转换为适当格式以创建动态图输出的正确方法 现在,我收到了错误信息: Error in lapply(X = x, FUN = "[", ..., drop = drop) : argument is missing, with no
Error in lapply(X = x, FUN = "[", ..., drop = drop) :
argument is missing, with no default
问题是,当我手动将Excel中的时间列修改为格式:h:mm:ss
,它就可以工作了。我不想在上传之前要求我的用户修改Excel中的.csv
服务器.R
尝试在代码中替换uploadedFile1$Time我收到以下错误:as.POSIXlt.default中的错误(uploadedFile1$Time,“%H:%M:%S”):不知道如何将“uploadedFile1$Time”转换为我在文件中忘记的类“POSIXlt”,后跟“.”尝试此格式=“%H:%M.%S”我将冒号更改为句号,但仍然收到相同的错误。.将冒号更改为句号只需在第一次上载文件1$Time时完成
library(xts)
library(shiny)
library(dygraphs)
shinyServer(function(input, output, session) {
# Upload the CSV File
uploadedFile1 <- reactive({
validate(need(input$file1, FALSE)) # This is like a better "if (is.null(input$file1)) return(NULL)"
uf1 <- read.csv(input$file1$datapath, header=TRUE, stringsAsFactors=FALSE)
uf2$Time <- strptime(uf2$Time, format= "%H:%M:%S")
})
uploadedFile2 <- reactive({
validate(need(input$file2, FALSE)) # This is like a better "if (is.null(input$file2)) return(NULL)"
uf2 <- read.csv(input$file2$datapath, stringsAsFactors=F)
uf2$Time <- strptime(uf2$Time, format= "%H:%M:%S")
})
observeEvent(uploadedFile1(), {
updateSelectizeInput(session, 'uploadChannels1', choices = names(uploadedFile1()))
})
observeEvent(uploadedFile2(), {
updateSelectizeInput(session, 'uploadChannels2', choices = names(uploadedFile2()))
})
output$graph <- renderDygraph({
# Clean up the loaded CSV File, convert Time column to a Time Object for Dygraph.
uploadedFile1 <- uploadedFile1()
uploadedFile2 <- uploadedFile2()
uploadedFile1$Time <- as.POSIXct(strptime(uploadedFile1$Time,"%H:%M:%S"))
uploadedFile2$Time <- as.POSIXct(strptime(uploadedFile2$Time,"%H:%M:%S"))
uploadedFile1$ctime <- strptime(paste(uploadedFile1$Time), "%Y-%m-%d %H:%M:%S")
uploadedFile2$ctime <- strptime(paste(uploadedFile2$Time), "%Y-%m-%d %H:%M:%S")
# Update the SelectInput and store the value in component5 to be used in the graph.
selectedInput1 <- input$uploadChannels1
selectedInput2 <- input$uploadChannels2
component5 <- uploadedFile1[, selectedInput1]
component6 <- uploadedFile2[, selectedInput2]
cbinded <- cbind(component5, component6)
xts(cbinded, uploadedFile1$Time, uploadedFile2$Time) %>%
dygraph()
})
})
library(xts)
library(shiny)
library(dygraphs)
shinyUI(fluidPage(
navbarPage("Data Graph",
tabPanel("Upload a CSV File:",
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
selectInput("uploadChannels1", label = "Choose a Temp. Rise Location",
choices = NULL),
fileInput('file2', 'Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
selectInput("uploadChannels2", label = "Choose a Temp. Rise Location",
choices = NULL),
tags$hr(),
checkboxInput('header', 'Header', TRUE),
radioButtons('sep', 'Separator',
c(Comma=',',
Semicolon=';',
Tab='\t'),
',')
),
mainPanel(
dygraphOutput('graph')
))
)
)))