यह प्रश्न this one से संबंधित है। दोनों एक ही कार्यक्षमता उत्पन्न कर सकते हैं, लेकिन कार्यान्वयन थोड़ा अलग है। एक महत्वपूर्ण अंतर यह है कि reactiveValue
एक कंटेनर है जिसमें कई मान हो सकते हैं, जैसे input$
। shiny documentation कार्यक्षमता को आमतौर पर reactive()
का उपयोग करके कार्यान्वित किया जाता है, लेकिन ज्यादातर मामलों में मुझे reactiveValues()
अधिक सुविधाजनक लगता है। क्या यहां कोई पकड़ है? क्या उन दोनों के बीच कोई अन्य बड़ा अंतर है जो मुझे पता नहीं हो सकता है? क्या ये दो कोड स्निपेट बराबर हैं?आर चमकदार: प्रतिक्रियाशील वैल्यू बनाम प्रतिक्रियाशील
देखें एक ही example code का उपयोग कर कार्यान्वित:
एक प्रतिक्रियाशील अभिव्यक्ति:
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)
एक प्रतिक्रियाशील मूल्य:
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) { myReactives <- reactiveValues() observe( myReactives$currentFib <- fib(as.numeric(input$n)) ) output$nthValue <- renderText({ myReactives$currentFib }) output$nthValueInv <- renderText({ 1/myReactives$currentFib }) }) shinyApp(ui = ui, server = server)
जब आप पूरा कर लें तो कृपया इस विषय को संदर्भ http://stackoverflow.com/documentation/shiny/topics –