这个问题关系到这一个.这两者可以生成相同的功能,但实现略有不同.一个显着的区别是a reactiveValue是一个可以有多个值的容器,比如input$.在闪亮的文档中,功能通常使用reactive(),但在大多数情况下我觉得reactiveValues()更方便.这里有捕获吗?我可能没有注意到这两者之间是否存在其他重大差异?这两个代码片段是否相同?
查看 使用以下实现的相同示例代码:
反应性表达:
library(shiny)
ui <- fluidPage(
shiny::numericInput(inputId = 'n',label = 'n',value = 2),
shiny::textOutput('nthValue'),
shiny::textOutput('nthValueInv')
)
fib <- function(n) ifelse(n<3, 1, fib(n-1)+fib(n-2))
server<-shinyServer(function(input, output, session) {
currentFib <- reactive({ fib(as.numeric(input$n)) })
output$nthValue <- renderText({ currentFib() })
output$nthValueInv <- renderText({ 1 / currentFib() })
})
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)反应值:
library(shiny)
ui <- fluidPage(
shiny::numericInput(inputId = 'n',label = 'n',value = 2),
shiny::textOutput('nthValue'),
shiny::textOutput('nthValueInv') …Run Code Online (Sandbox Code Playgroud)