使用带有r-shiny的ggploy时出错(警告:中的错误:`Filter()`输入`..1`有问题。) [英] Getting error while using ggplot with r-shiny (Warning: Error in : Problem with `filter()` input `..1`.)
本文介绍了使用带有r-shiny的ggploy时出错(警告:中的错误:`Filter()`输入`..1`有问题。)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试开发我的第一个R闪亮应用程序。我正在尝试创建一个CheckboxGroupInput()。在我的数据集中,有两种不同类型的飞机。因此,用户可以决定是查看两种机型的折线图,还是只查看其中一种机型的折线图
我运行的错误是:
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))
})
这篇关于使用带有r-shiny的ggploy时出错(警告:中的错误:`Filter()`输入`..1`有问题。)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文