如何保存输出以便稍后在 Shiny R 的另一个输出中使用它
How to save an output to use it later in another output in Shiny R
我想使用闪亮的 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) }
})
我不确定,但我认为您正在寻找:
reactive()
或 reactiveValues()
。
我认为更清晰的版本是使用 reactive()
,但为了更接近您的代码片段,我将使用后者并使用 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)
我想使用闪亮的 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) }
})
我不确定,但我认为您正在寻找:
reactive()
或 reactiveValues()
。
我认为更清晰的版本是使用 reactive()
,但为了更接近您的代码片段,我将使用后者并使用 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)