-->

Error :Result must have length 12813, not 0?

2019-09-29 05:39发布

问题:

I was asked to do the coding project for a job as an intern in a company but I wasnt able to complete it. However I didn't get the job I wanted to just complete the thing . The error that arrives is:

Error :Result must have length 12813, not 0

Here is my code:

library(shiny)
library(dplyr)
stock<-read.csv("thafinal2.0.csv")

ui <- fluidPage(
dateInput(inputId = 'date1',label = 'Start',value = "2017-08-20"),
dateInput(inputId = 'date2',label = 'Stop',value = "2018-08-20"),
tabPanel("stock", DT::dataTableOutput("table")))
server <- function(input, output) {
output$table<-DT::renderDataTable({
stock %>%
filter(stock$date >= "2018-01-05" & stock$date <= "2018-01-03")
stock })}

shinyApp(ui, server)

I want to select data with in a range that I want.

回答1:

Answer goes out to Dason. The problem is in code:

filter(stock$date >= "2018-01-05" & stock$date <= "2018-01-03")

You filter simultanously dates later than "2018-01-05" and earlier than "2018-01-03" this kind of operation results to empty set with length 0.

If you change to:

filter(stock$date <= "2018-01-05" & stock$date >= "2018-01-03")

It should work OK.



标签: r subset dt