【发布时间】:2016-01-22 06:26:36
【问题描述】:
我有数据要绘制为用户上传的系列。但是,数据是一年的,我想显示 2 个月,例如 1 月和 2 月,当用户需要分析这几个月的模式时。这就是为什么我认为 dateRangeInput 可能有用但我不知道如何与 plot 绑定?
数据:http://www.filedropper.com/quo
已编辑:我使用响应式参数来获取输入。但是,它显示另一个错误: charToDate(x) 中的错误: 字符串不是标准的明确格式。
library(shiny)
shinyUI(fluidPage(
titlePanel("Time Series Study"),
sidebarLayout(
sidebarPanel(
fileInput('file2', 'Choose Quotation File:', accept=c('text/csv', 'text/comma-separated-values,text/plain', '.csv'), multiple = FALSE),
dateRangeInput("range",
"Date Range:",
start = "start",
end = "end",
min = "2012.01.01",
max = "2012.01.31")
),
mainPanel(
plotOutput("distPlot") ) ) ))
#server.r
library(shiny)
library(ggplot2)
shinyServer(function(input, output) {
dataInput <- reactive({
`uploadedsamplefile` <- read.csv(input$file2$datapath, sep=";",check.names = FALSE)
uploadedsamplefile1 <- uploadedsamplefile
xx<-cbind(`uploadedsamplefile1`[1:4])
xx$`Datee` <- as.Date( xx$`Datee`, '%d.%m.%Y')
xx$`Datee` <- subset( xx$`Datee`, as.Date("input$start") <= xx$`Datee` && xx$`Datee` <= as.Date("input$end"))
})
output$distPlot <- renderPlot({
y <- ggplot(xx, aes(x=`Datee`)) + geom_line(aes(y=(`A`), colour = "A")) + geom_line(size=1,aes(y=(`B`), colour = "B")) +
geom_line(size=1,aes(y=(`C`), colour = "C"))
y }) })
【问题讨论】:
-
创建一个
reactive()表达式来存储.csv 文件中的数据,然后使用daterangeinput根据范围对数据进行子集化 -
我尝试使用但后来我遇到了新问题。
标签: r ggplot2 shiny time-series timeserieschart