I keep getting the following Inf/-Inf errors when I attempt to subset a data frame in Shiny based on the indices of the dates the user selects in a sliderInput control.
Warning in min(inputData$rawdata$TmStamp) :
no non-missing arguments to min; returning Inf
Warning in max(inputData$rawdata$TmStamp) :
no non-missing arguments to max; returning -Inf
Warning in min(inputData$rawdata$TmStamp) :
no non-missing arguments to min; returning Inf
Warning in max(inputData$rawdata$TmStamp) :
no non-missing arguments to max; returning -Inf
Warning: Error in seq.int: 'to' must be a finite number
My code is below. I am rendering the control in the server using renderUI so it can be reactive to the sliderInput control. I think the problem is that, to start with, the renderDataTable function doesn't know the indices should be the 1 and the # rows of the data frame (input$rawdata). However, I do not know how to fix this. How do I get this to work properly? I don't understand why raw_begin_ind and raw_end_ind aren't being set right away (if that's the problem). Thank you.
output$rawDateRange <- renderUI({
tagList(
tags$style(type = 'text/css', '#raw_slider .irs-grid-text {color: black; font-size: 12px; transform: rotate(-90deg) translate(-20px)}'),
div(id = 'raw_slider',
sliderInput(inputId='rawDateRange',
label='Select Time Period to Show:',
min = as.Date(min(inputData$rawdata$TmStamp)),
max = as.Date(max(inputData$rawdata$TmStamp)),
value = c(as.Date(min(inputData$rawdata$TmStamp)),as.Date(max(inputData$rawdata$TmStamp)))
)
)
)
})
observeEvent(input$rawDateRange,
{
raw_begin_ind <- min(which(substr(inputData$rawdata$TmStamp,1,10) == input$rawDateRange[1]))
raw_end_ind <- max(which(substr(inputData$rawdata$TmStamp,1,10) == input$rawDateRange[2]))
output$rawdata <- renderDataTable({
inputData$rawdata[raw_begin_ind:raw_end_ind,]
})
}
)
cat
to display values in console in order to debug your code. For example just beforewhich(min(...))
insertcat(substr(inputData$rawdata$TmStamp,1,10),'\n')
to make sure the condition works as you think. – Waldiinput$...
may beNULL
or empty, defeating the general assumption of what to expect out of inputs. This often cascades, resulting in a 0-length (0-row) reactive-data cascading to follow-on elements. This is one reason wherereq(...)
is very useful: it stops any further work in a reactive block (and subsequent dependent blocks) when its input is unstable. – r2evansreq(inputData$rawdata)
to the beginning (first expression) of these two reactive blocks and see if it ameliorates the problem. – r2evansmin(which(...))
is a slower version ofwhich(...)[1]
; similarlymax(which(...))
is the slower version oftail(which(...),1)
. Granted, the difference in time is miniscule. But the results are not equivalent:min(which(...))
returnsInf
when none of the...
condition is true; similarlymax(which(...))
returns-Inf
with nothing found in...
. Perhaps that will be a problem, too? (I know it's not the warning you're showing in the question.) – r2evans