R:为不同的输出控件重用冗长的计算

R:为不同的输出控件重用冗长的计算,r,shiny,R,Shiny,我在server.R中有以下代码: library(shiny) source("helpers.R") shinyServer(function(input, output) { output$txtOutput1 <- renderText({ someLengthyComputation(input$txtInput)[1] }) output$txtOutput2 <- renderText({ someLeng

我在server.R中有以下代码:

library(shiny)

source("helpers.R")

shinyServer(function(input, output) {
    output$txtOutput1 <- renderText({ 
        someLengthyComputation(input$txtInput)[1]
    })
    output$txtOutput2 <- renderText({ 
        someLengthyComputation(input$txtInput)[2]
    })
    output$txtOutput3 <- renderText({ 
        someLengthyComputation(input$txtInput)[3]
    })
})
库(闪亮)
来源(“helpers.R”)
shinyServer(功能(输入、输出){

output$txtoput1您只需将
someLengthyComputation
放入表达式中:

shinyServer(function(input, output) {
    someExpensiveValue <- reactive({
        someLengthyComputation(input$txtInput)
    })

    output$txtOutput1 <- renderText({ 
        someExpensiveValue()[1]
    })

    output$txtOutput2 <- renderText({ 
        someExpensiveValue()[2]
    })

    output$txtOutput3 <- renderText({ 
        someExpensiveValue()[3]
    })
})
shinyServer(功能(输入、输出){
一些昂贵的价值