我有以下數據集時:無類錯誤創建一個閃亮的應用
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