我有以下数据集时:无类错误创建一个闪亮的应用
Type <- c("Choice 1", "Choice 1", "Choice 1", "Choice 1", "Choice 1",
"Choice 1")
Date <- c("02-02-2016", "02-03-2016", "02-04-2016", "02-05-2016",
"02-06-2016", "02-07-2016")
Sentiment <- c(1, 2, 3, 4, 2, 3)
df <- data.frame(Type, Date, Sentiment)
现在我建立一个闪亮的应用程序,允许您过滤日期范围,并选择一个类型。那么应该给你一个子集中所有情感值的直方图。
因此,我创建了下面的闪亮代码
df <- read.csv2("sample.csv", stringAsFactors = F)
df$Date <- as.Date(df$Date, format = "%d-%m-%Y")
library(shiny)
ui <- fluidPage(tabsetPanel(
#Sliders for the first panel
tabPanel("Tab 1",sidebarPanel(
dateRangeInput("daterange1", "Date range:",
start = "2015-01-01",
end = "2015-12-31"),
selectInput("select", label = h3("Select box"),
choices = list("Choice 1" = 1,"Choice 2" = 2,"Choice 3" = 3),
selected = 1)),
mainPanel(plotOutput("coolplot"))),
#Sliders for the second panel
tabPanel("Tab 2", mainPanel("the results of tab2"))
))
server <- function(input, output) {
filtered <- reactive({
if (is.null(input$select)) {
return(NULL) }
df %>% filter(Date >= input$dateRangeInput[1],
Date <= input$dateRangeInput[2],
Type == input$select)
})
output$coolplot <- renderPlot({
ggplot(filtered(), aes(Sentiment)) + geom_histogram()
})
}
shinyApp(ui = ui, server = server)
然而,当我跑我得到以下错误:
incorrect length (0), expecting: 10
,我应该怎样做才能避免这个错误有什么想法?
'ggplot(过滤,AES(观点))'应该是'ggplot(过滤(),AES(观点) )',因为'filtered'是一个**函数**返回一些东西。 – nrussell
非常感谢nrussell!它带来了这个bug。直到现在,我遇到了以下错误...(见编辑)。有什么想法吗? –
'gincorrect长度(0),期望:10'是* *完全错误消息? – nrussell