我正在尝试从R / Shiny中的API查询日期范围。我使用dateRangeInput指定范围,并且API文档指定调用为:
spuddate,值应为RFC3339格式,在属性上开始钻探的最新日期。例如:spuddate = gt(2006-01-02T15:04:05Z)spuddate = le(2017-03)。
我如何正确执行此操作?
我已经尝试使用anytime和rfc3339的几种方法,但是我不断遇到各种错误。我怀疑这一定与我在服务器中构造输入调用的方式有关。
#UI - Obviously there are more but for sake of brevity here is the subset
sidebarPanel(
fluidRow(
column(12,
selectizeInput('stateSelect','STATE', choices= paste0(state.abb, sep=''), multiple=FALSE))
),
fluidRow(
column(12,
selectizeInput('directionSelect','HOLE DIRECTION', choices= c('H','V','D','U'), multiple=FALSE))
),
fluidRow(
column(12,
dateRangeInput("dateSelect", label = h3("Spud Date range")))
),
#Server Try So Far -- Obviously there are more but for sake of brevity here is the subset
observeEvent(input$select, {
wellInfo <- GET("https://di-api.drillinginfo.com/v2/direct-access/producing-entities",
add_headers(c('X-API-KEY' = key, 'Authorization' = addToken, 'Accept' = 'text/xml')),
query=list(drilltype = dput(input$directionSelect), state = dput(input$stateSelect),
spuddate = (rfc3339(anytime(input$dateSelect[1])),rfc3339(anytime(input$dateSelect[2]))),
pagesize = 100000))
})
我只想让查询结束。它可以在不调用spuddate的情况下工作(即仅查询状态和rilltype)。任何帮助,将不胜感激!谢谢。
答案 0 :(得分:0)
好的,想出了一种蛮力解决方案。
date1 <- paste('btw(',date(anytime(input$dateSelect[1])),
',',date(anytime(input$dateSelect[2])),')', sep='')
wellInfo <- GET("https://di-api.drillinginfo.com/v2/direct-access/producing-entities",
add_headers(c('X-API-KEY' = key, 'Authorization' = addToken, 'Accept' = 'text/xml')),
query=list(drilltype = dput(input$directionSelect), state = dput(input$stateSelect),
spuddate = dput(date1),
#spuddate <= (as.POSIXct(as.character(input$dateSelect2, format = '%Y-%m'))),
pagesize = 100000))