序列选择和打印错误-R
我有数据,包括日期、温度和记录测量的海拔高度。我正在尝试使用R Shining创建一个简单的反应性绘图,其中绘图根据感兴趣的高程边界而变化。一旦定义了边界,它将获取每天这些边界的平均值并绘制它们。下面是一个示例数据集(很抱歉生成此数据集的时间过长): 这是我的服务器。R:序列选择和打印错误-R,r,plot,shiny,seq,R,Plot,Shiny,Seq,我有数据,包括日期、温度和记录测量的海拔高度。我正在尝试使用R Shining创建一个简单的反应性绘图,其中绘图根据感兴趣的高程边界而变化。一旦定义了边界,它将获取每天这些边界的平均值并绘制它们。下面是一个示例数据集(很抱歉生成此数据集的时间过长): 这是我的服务器。R: #=================== # server.R #=================== library(plyr) shinyServer(function(input,output){
#===================
# server.R
#===================
library(plyr)
shinyServer(function(input,output){
passData <- reactive({
campbell_out <- campbell_out[campbell_out$day %in%
seq.Date(input$dateRange[1],
input$dateRange[2], by = "days"),]
campbell_out <- campbell_out[campbell_out$sonde.elev %in%
seq(as.numeric(input$minimumElevation),
as.numeric(input$maximumElevation), by=0.000001),]
campbell_out
})
output$theGraph <- renderPlot({
graphData <- ddply(passData(),.(day),numcolwise(mean))
theGraph <- plot(temperature_c~day,data=graphData, ylab = "Temperature (c)", xlab = "Time")
print(theGraph)
})
})
当我运行一个类似的脚本,根据特定的日期和高程对数据集进行采样,然后绘制数据集时,效果很好。所以问题似乎出在我闪亮的代码上。如果有人能告诉我哪里出了问题,我将不胜感激 尝试将这些行添加到您的
passData
reactive(处理reactive初始化警告)中:
passData
#===================
# ui.R
#===================
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Stack Overflow Lough"),
sidebarPanel(
dateRangeInput(inputId = "dateRange",
label = "Date Range",
start = "2016-01-01",
max = Sys.Date()
),
sliderInput(inputId = "minimumElevation",
label="Feet (ASL) - Minimum",
min = 215,
max = 290,
value = 215,
step = 1),
sliderInput(inputId = "maxmimumElevation",
label="Feet (ASL) - Maximum",
min = 215,
max = 290,
value = 290,
step = 1)
),
mainPanel(plotOutput("theGraph"))
)
)
#===================
# server.R
#===================
library(plyr)
shinyServer(function(input,output){
passData <- reactive({
campbell_out <- campbell_out[campbell_out$day %in%
seq.Date(input$dateRange[1],
input$dateRange[2], by = "days"),]
campbell_out <- campbell_out[campbell_out$sonde.elev %in%
seq(as.numeric(input$minimumElevation),
as.numeric(input$maximumElevation), by=0.000001),]
campbell_out
})
output$theGraph <- renderPlot({
graphData <- ddply(passData(),.(day),numcolwise(mean))
theGraph <- plot(temperature_c~day,data=graphData, ylab = "Temperature (c)", xlab = "Time")
print(theGraph)
})
})
Warning: Error in seq.default: 'to' must be of length 1
passData <- reactive({
req(input$dateRange[1])
req(input$dateRange[2])
req(input$minimumElevation)
req(input$maximumElevation)
campbell_out <- campbell_out[campbell_out$day %in%
seq.Date(input$dateRange[1],
input$dateRange[2],by = "days"),]
print(as.numeric(input$minimumElevation))
print(as.numeric(input$maximumElevation))
campbell_out <- campbell_out[campbell_out$sonde.elev %in%
seq(as.numeric(input$minimumElevation),
as.numeric(input$maximumElevation),by = 0.000001),]
campbell_out
})