R 从指定日期运行应用程序时出错。警告:错误:结果的长度必须为121728,而不是0
我正在尝试创建一个闪亮的应用程序,它使用一个数据集Shinny_clean,并创建一个ggplot线条图,显示x轴上的模型功率预测与时间的关系。这是我的数据R 从指定日期运行应用程序时出错。警告:错误:结果的长度必须为121728,而不是0,r,ggplot2,shiny,R,Ggplot2,Shiny,我正在尝试创建一个闪亮的应用程序,它使用一个数据集Shinny_clean,并创建一个ggplot线条图,显示x轴上的模型功率预测与时间的关系。这是我的数据 Timestamp Turbine_ID Grd_Prod_Pwr_Avg Amb_WindSpeed_Max Amb_WindSpeed_Min Amb_WindSpeed_Avg Amb_WindSpeed_Std 1 2017-06-02 00:00:00 T07 891.6
Timestamp Turbine_ID Grd_Prod_Pwr_Avg Amb_WindSpeed_Max Amb_WindSpeed_Min Amb_WindSpeed_Avg Amb_WindSpeed_Std
1 2017-06-02 00:00:00 T07 891.6 14.2 2.8 7.8 1.4
2 2017-06-02 00:00:00 T06 1338.1 17.2 3.8 9.3 1.5
3 2017-06-02 00:00:00 T11 677.6 16.3 3.5 7.5 1.2
4 2017-06-02 00:00:00 T01 656.1 17.5 1.2 7.2 1.7
5 2017-06-02 00:10:00 T01 759.6 16.4 2.1 7.6 1.4
6 2017-06-02 00:10:00 T06 1145.0 13.9 3.3 8.6 1.3
Amb_WindDir_Abs_Avg Nac_Direction_Avg Min_Windspeed1 Max_Windspeed1 Avg_Windspeed1 Var_Windspeed1 Min_Windspeed2
1 106.2 93.6 7.1 12.0 9.7 0.63 6.8
2 84.3 98.4 7.1 12.0 9.7 0.63 6.8
3 90.5 99.6 7.1 12.0 9.7 0.63 6.8
4 106.8 116.2 7.1 12.0 9.7 0.63 6.8
5 98.8 116.2 7.9 12.1 10.1 0.73 7.4
6 96.2 98.4 7.9 12.1 10.1 0.73 7.4
Max_Windspeed2 Avg_Windspeed2 Var_Windspeed2 Min_AmbientTemp Max_AmbientTemp Avg_AmbientTemp Min_Pressure Max_Pressure
1 10.6 8.6 0.40 21 22 22 1008 1009
2 10.6 8.6 0.40 21 22 22 1008 1009
3 10.6 8.6 0.40 21 22 22 1008 1009
4 10.6 8.6 0.40 21 22 22 1008 1009
5 10.5 8.9 0.47 21 22 22 1008 1009
6 10.5 8.9 0.47 21 22 22 1008 1009
Avg_Pressure Min_Humidity Max_Humidity Avg_Humidity results model
1 1009 68 69 68 788.8035 WGT_RF_NN
2 1009 68 69 68 1283.3277 WGT_RF_NN
3 1009 68 69 68 712.6971 WGT_RF_NN
4 1009 68 69 68 651.6901 WGT_RF_NN
5 1009 68 69 68 734.4558 WGT_RF_NN
6 1009 68 69 68 940.1862 WGT_RF_NN
我的ui工作得很好。但当我运行应用程序时,我在中得到一个警告错误:结果的长度必须为121728,而不是0。我怀疑这与过滤有关,但我无法解决。这是我运行应用程序时看到的
这是我的密码:
library(shiny)
library(ggplot2)
library(tidyverse)
library(lubridate)
shiny_clean <- read.csv("shiny_clean.csv", stringsAsFactors = FALSE)
shiny_clean <- filter(shiny_clean, shiny_clean$Timestamp > as.Date("2017-06-01"))
ui <- fluidPage(
titlePanel("Machine learning ensemble model to predict wind farm power output"),
sidebarPanel(
dateInput("dateInput", "Date", min = min(shiny_clean$Timestamp), max =max(shiny_clean$Timestamp), value = min(shiny_clean$Timestamp)),
radioButtons("typeInput", "Turbine",
choices = c("T01", "T06", "T07", "T11"),
selected = "T01"),
uiOutput("modelOutput")
),
mainPanel(
plotOutput("coolplot"),
br(), br(),
tableOutput("results")
)
)
server <- function(input, output) {
output$modelOutput <- renderUI({
selectInput("modelInput", "Model",
sort(unique(shiny_clean$model)),
selected = "WGT_RF_NN")
})
filtered <- reactive({
if (is.null(input$modelInput)) {
return(NULL)
}
shiny_clean %>%
filter(Timestamp == input$dateInput,
Turbine_ID == input$typeInput,
model == input$modelinput
)
})
output$coolplot <- renderPlot({
if (is.null(filtered())) {
return()
}
ggplot()+
geom_line(data = filtered, aes(x=Timestamp, y=results))
})
output$results <- renderTable({
filtered()
})
}
shinyApp(ui = ui, server = server)
只是过滤部分的一些小的修正。您忘记了$modelInput中的大写字母i。需要将时间戳调整为日期。在绘图中,您需要使用筛选而不是仅使用筛选 以下是完整的代码:
library(shiny)
library(ggplot2)
library(tidyverse)
library(lubridate)
shiny_clean <- read.csv("shiny_clean.csv", stringsAsFactors = FALSE)
shiny_clean <- filter(shiny_clean, shiny_clean$Timestamp > as.Date("2017-06-01"))
ui <- fluidPage(
titlePanel("Machine learning ensemble model to predict wind farm power output"),
sidebarPanel(
dateInput("dateInput", "Date", min = min(shiny_clean$Timestamp), max =max(shiny_clean$Timestamp), value = min(shiny_clean$Timestamp)),
radioButtons("typeInput", "Turbine",
choices = c("T01", "T06", "T07", "T11"),
selected = "T01"),
uiOutput("modelOutput")
),
mainPanel(
plotOutput("coolplot"),
br(), br(),
tableOutput("results")
)
)
server <- function(input, output) {
output$modelOutput <- renderUI({
selectInput("modelInput", "Model",
sort(unique(shiny_clean$model)),
selected = "WGT_RF_NN")
})
filtered <- reactive({
if (is.null(input$modelInput)) {
return(NULL)
}
shiny_clean %>%
filter(as.Date(Timestamp) == as.Date(input$dateInput),
Turbine_ID == input$typeInput,
model == input$modelInput
)
})
output$coolplot <- renderPlot({
if (is.null(filtered())) {
return()
}
ggplot()+
geom_line(data = filtered(), aes(x=Timestamp, y=results))
})
output$results <- renderTable({
filtered()
})
}
shinyApp(ui = ui, server = server)
library(shiny)
library(ggplot2)
library(tidyverse)
library(lubridate)
shiny_clean <- read.csv("shiny_clean.csv", stringsAsFactors = FALSE)
shiny_clean <- filter(shiny_clean, shiny_clean$Timestamp > as.Date("2017-06-01"))
ui <- fluidPage(
titlePanel("Machine learning ensemble model to predict wind farm power output"),
sidebarPanel(
dateInput("dateInput", "Date", min = min(shiny_clean$Timestamp), max =max(shiny_clean$Timestamp), value = min(shiny_clean$Timestamp)),
radioButtons("typeInput", "Turbine",
choices = c("T01", "T06", "T07", "T11"),
selected = "T01"),
uiOutput("modelOutput")
),
mainPanel(
plotOutput("coolplot"),
br(), br(),
tableOutput("results")
)
)
server <- function(input, output) {
output$modelOutput <- renderUI({
selectInput("modelInput", "Model",
sort(unique(shiny_clean$model)),
selected = "WGT_RF_NN")
})
filtered <- reactive({
if (is.null(input$modelInput)) {
return(NULL)
}
shiny_clean %>%
filter(as.Date(Timestamp) == as.Date(input$dateInput),
Turbine_ID == input$typeInput,
model == input$modelInput
)
})
output$coolplot <- renderPlot({
if (is.null(filtered())) {
return()
}
ggplot()+
geom_line(data = filtered(), aes(x=Timestamp, y=results))
})
output$results <- renderTable({
filtered()
})
}
shinyApp(ui = ui, server = server)