R 将反应值传递给函数并访问反应属性
我想在将一个无功电源发送到一个无功端点之前,通过多个无功导体获取一个无功电源 一般示例:R 将反应值传递给函数并访问反应属性,r,shiny,R,Shiny,我想在将一个无功电源发送到一个无功端点之前,通过多个无功导体获取一个无功电源 一般示例: x <- reactive({ function(input$var) }) y <-reactive({ function(x) }) output$display<-renderText({ y()$attr }) x一个问题可能是定义header\u call时,url后面缺少括号url是一个闭包,url()返回url字符串 另外,renderText是被动的,因此您可以从那里
x <- reactive({ function(input$var) })
y <-reactive({ function(x) })
output$display<-renderText({ y()$attr })
x一个问题可能是定义header\u call
时,url
后面缺少括号url
是一个闭包,url()
返回url字符串
另外,renderText
是被动的,因此您可以从那里调用HEAD(url())
:
这对我很有用(我删除了header\u call=reactive({HEAD(url)})
):
输出$REC
# Install packages if needed
packageNeeds <- c('shiny', 'httr', 'dataRetrieval')
packageNeeds <- packageNeeds[!packageNeeds %in% rownames(installed.packages())]
if(length(packageNeeds)>0){
install.packages(packageNeeds, repos='http://cran.cnr.Berkeley.edu')
}
library(shiny)
library(httr)
library(dataRetrieval)
shinyApp(
ui = fluidPage(
fluidRow(
wellPanel(
selectInput("site", label = p("Pick a site"), choices = list('01594440', 'sysys')),
selectInput("start", label = p("pick a date"), choices = list('1985-01-01', "xyz")))),
fluidRow(wellPanel(verbatimTextOutput("URL"))),
fluidRow(wellPanel(verbatimTextOutput("REC")))),
server = function(input, output, session){
url<-reactive({
# Here the user inputs are used to constuct a url -
# but really this could be any function that I'd like to take the output of
# and pass it on to other functions and/or subeset
# before sending to a reactive output
constructWQPURL(paste("USGS",input$site,sep="-"),
c('01075','00029','00453'),
input$start, endDate = "")
})
# This is the function I've passed the reactive value to
# it returns an object with a headers attributes that has the
# 'total-result-count' attribute I want
header_call = reactive({HEAD(url)})
output$URL<-renderText({
# The url displays fine
url()
})
output$REC<-renderText({
# The record count from the header pull does not display
# the value is the number of records stored as a string
header_call()$headers$'total-result-count'
})
}
)
output$REC<-renderText({
# The record count from the header pull does not display
# the value is the number of records stored as a string
#header_call()
HEAD(url())$headers$'total-result-count'
})