Tingolfin Tingolfin - 7 days ago 5
R Question

R shiny: validate(need()) with dateRangeInput

I've read the help pages and shiny webpages on

validate()
and
need()
10 times, googled all variations I could think of, but I simply cannot find what is wrong with my code.

The only thing I require is for my app to show a custom error instead of the (empty) plot when a user inputs a wrong date range = 2nd date earlier than the 1st.

output$plotTemp <- renderPlot({
req(input$button)
validate(need(input$datums[1] < input$datums[2], "error: end date earlier than start"))
isolate({buttonFeedbackServer("button", { # if validate = ok, run functions
importdata(input$jaartal)
weerstation <- which(weerstations == input$weerstation)
temperatuur(input$datums, weerstation) # create plot
})
})
})


I get this error now: no applicable method for 'validate' applied to an object of class "NULL"

I bet it's gonna be something stupid, but I spent hours and hours on this without seeing it...

Without
validate()
everything works perfect, so it's no mistake in other code.

My R, Rstudio and all packages have been updated last week.

Answer

Other packages, including jsonlite have a validate function. This error can occur when you accidentally are using a validate function from a different package. Try using shiny::validate instead to make sure you are using the correct validate.