繁体   English   中英

使用带有 r-shiny 的 ggplot 时出错(警告:错误:`filter()` 输入 `..1` 出现问题。)

[英]Getting error while using ggplot with r-shiny (Warning: Error in : Problem with `filter()` input `..1`.)

我正在尝试开发我的第一个 R shiny 应用程序。 我正在尝试创建一个 checkboxGroupInput()。 在我的数据集中,有两种不同类型的飞机。 因此,用户可以决定是要查看两种机型的 plot 还是只查看其中一种机型

我正在运行的错误是:

Warning: Error in : Problem with `filter()` input `..1`.
x Input `..1` must be of size 5514 or 1, not size 25.
i Input `..1` is `aircrash %in% input$aircrafttypeInput`.

我的用户界面代码如下:


library(shiny)
library(shinythemes)
library(dplyr)
library(ggplot2)


aircrash <-read.csv("aircrash_clean_data.csv", header = T)

# Define UI for application that draws a histogram
ui <- fluidPage(
     navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
                           "Aircrash Investigation Analysis", id="nav",
                tabPanel("Crashes",
                         sidebarLayout(
                             sidebarPanel(
    sliderInput("bin", "Please select the bin width:",
                min=0, max=20, value=4, step=1),
    checkboxGroupInput("aircrafttypeInput", "Select the Aircraft Type:",
                       choices = c("Civilian",
                                   "Military"),
                       selected = c("Civilian", "Military"))
    
                                        
),
mainPanel(
    plotOutput("plot", width = "75%",height="530px"),
    plotOutput("Aircrafttypecount")
)
)
)
)    
)

我的服务器代码是:

server <- function(input, output) {

    output$plot <- renderPlot({
        # generate bins based on input$bins from ui.R
        ggplot(data=aircrash, aes(x= crash_year))+
            geom_histogram(binwidth = as.numeric(input$bin))
    })
    
    d <- reactive({
        filtered <-
            aircrash %>%
            filter(aircrash %in% input$aircrafttypeInput)   
        
    }) 
    
    output$Aircrafttypecount <-renderPlot({
        ggplot(data=d(), aes(x= crash_year, y=stat(count), color =crash_opr_type ))+
            geom_line(stat = "count", size = 1.5)+theme_bw()+
            theme(plot.title = element_text(color = "black", size = 20, face = "bold", hjust = 0.5), 
                  axis.title.x =element_text(color = "black", size = 14, face = "bold", hjust = 0.5),
                  axis.title.y = element_text(color = "black", size = 14, face = "bold", hjust = 0.5))+
            labs(y = "Number of Aircrashes",x="Year",title = "Number of Crashes per Year",color = "Aircraft Type")+
            expand_limits(y=c(0,100)) + 
            scale_y_continuous(breaks=seq(0, 100, 20))+coord_cartesian(xlim=c(1908, 2028)) + 
            scale_x_continuous(breaks=seq(1908, 2028, 10))
    })
    
}

谢谢您的帮助!

你需要sum

d <- reactive({
        filtered <-
            aircrash %>%
            filter(sum(aircrash %in% input$aircrafttypeInput))  
        
    }) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM