I am trying to make a shiny app in which when choosing two dates it gives you the difference of another variable included in the same data frame, but the final result always gives me an error message in the app, which is: Error: comparison (3) is possible only for atomic and list types
.
The app code is the following:
if (interactive()) {
base <- readxl::read_excel("/Users/jorge/Downloads/salidacapitales.xlsx")
base$Fecha <-as.Date(base$Fecha,"%m/%d/%Y")
shinyApp(
ui = basicPage(
dateInput("fecha1", "Ingresa una fecha inicial", value = "2020-12-01"),
dateInput("fecha2", "Ingresa una fecha final", value = "2021-05-07"),
tableOutput("output")
),
server = function(input, output){
dato1 <- reactive({base %>%
dplyr::filter(Fecha == as.character(input$fecha1))})
dato2 <- reactive({base %>%
dplyr::filter(Fecha == as.character(input$fecha2))})
x <- reactive({dato1$`Total en dólares` - dato2$`Total en dólares`})
output$output <- renderPrint({if( x < 0 ){
print(paste("Hubo una entrada de capitales por",abs(x),"millones de dólares"))
} else {
print(paste("Hubo una salida de capitales por",abs(x),"millones de dólares"))
} })
}
)
}
Anyone have any idea what my mistake could be?
Thanks for help me