gpt4 book ai didi

r - 将 react 值传递给函数并访问 react 属性

转载 作者:行者123 更新时间:2023-12-04 18:04:22 24 4
gpt4 key购买 nike

我想在将电抗源发送到电抗端点之前通过多个电抗导体获取电抗源。

通用示例:

x <- reactive({ function(input$var) })

y <-reactive({ function(x) })

output$display<-renderText({ y()$attr })

下面是一个具体的例子。

提前致谢

# 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'
})
}
)

最佳答案

一个问题可能是您在定义 header_call 时缺少 url 后的括号。 url 是一个闭包,url() 返回 URL 字符串。

此外,renderText 是响应式的,因此您可以从那里调用 HEAD(url()):

这对我有用(我删除了 header_call = reactive({HEAD(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()
HEAD(url())$headers$'total-result-count'
})

关于r - 将 react 值传递给函数并访问 react 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29659902/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com