【问题标题】:How to save an output to use it later in another output in Shiny R如何保存输出以便稍后在 Shiny R 的另一个输出中使用它
【发布时间】:2017-05-30 07:24:27
【问题描述】:

我想将闪亮的 2 个输出的结果用于另一个输出进行绘图: 第一个输出是下面的soq1:

output$soq <- renderTable({

     if (input$selectedLevels == "Technical Junior")
     {soq1<-sum(simplegap1[,input$Candidate]>0)}

     else if (input$selectedLevels == "Entry Level")
     {soq1<-sum(simplegap2[,input$Candidate]>0)}

     else if (input$selectedLevels == "Product Owner")
     {soq1<-sum(simplegap3[,input$Candidate]>0)}

     else if (input$selectedLevels == "Technical Leader")
     {soq1<-sum(simplegap4[,input$Candidate]>0)}

     else if (input$selectedLevels == "Senior Manager") 
     {soq1<-sum(simplegap5[,input$Candidate]>0)} 
     }, include.rownames = TRUE ,  bordered = TRUE ,hover = TRUE, align = "c" ) 

我稍后要使用的第二个输出是:

output$suq <- renderTable({

     if (input$selectedLevels == "Technical Junior")
     {suq1<-sum(simplegap1[,input$Candidate]<0)}

     else if (input$selectedLevels == "Entry Level")
     {suq1<-sum(simplegap2[,input$Candidate]<0)}

     else if (input$selectedLevels == "Product Owner")
     {suq1<-sum(simplegap3[,input$Candidate]<0)}

     else if (input$selectedLevels == "Technical Leader")
     {suq1<-sum(simplegap4[,input$Candidate]<0)}

     else if (input$selectedLevels == "Senior Manager") 
     {suq1<-sum(simplegap5[,input$Candidate]<0)} 
     }, include.rownames = TRUE ,  bordered = TRUE ,hover = TRUE, align = "c" )

稍后我想将结果 soq1 和 suq1 用于另一个输出进行计算:

output$qsplot <- renderPlot({

      if (input$selectedLevels == "Technical Junior")
      { plot(x,-x,type = "p",main = "Qualification Space",xlim = c(0,1),ylim = c(-1,0), xlab = "SOQ",ylab = "SUQ")
       points(soq1,suq1,type="o",pch=20) }

    })

【问题讨论】:

    标签: r variables output assign


    【解决方案1】:

    我不确定,但我认为您正在寻找: reactive()reactiveValues()。 我认为更简洁的版本是使用reactive(),但为了更接近您的代码sn-p,我将使用后者并使用renderTable() 函数执行数据修改。

    mat <- matrix(1:9, ncol = 3)
    
    ui <- fluidPage(
      tableOutput("table1"),
      tableOutput("table2")
    )
    
    server <- function(input, output, session){
      global <- reactiveValues(mat = NULL)
      
      output$table1 <- renderTable({
        matNew <- mat
        # edit the table
        matNew[, 1] <- 1
        global$mat <- matNew
      })
    
      output$table2 <- renderTable({
        if(!is.null(global$mat)){
          return(global$mat)
        }
      })
    }
    
    shinyApp(ui = ui, server = server)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-23
      • 1970-01-01
      • 2021-05-03
      • 1970-01-01
      • 2017-08-04
      • 2015-12-31
      相关资源
      最近更新 更多