2017-01-15 8 views
1

Я хочу использовать результаты 2 выхода в блестящем на другой выход для черчения: Первый выход soq1 ниже:Как сохранить выход, чтобы использовать его позже в другом выходе в Shiny R

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) } 

    }) 

ответ

0

Я не уверен, но я думаю, что вы либо ищете: 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) 

P.S: Я был немного не уверен, если я получаю вопрос правильно. В случае, если вы заинтересованы здесь, это отличная статья о том, как легко ответить на ваши вопросы :). How to make a great R reproducible example?