R:将无功输出写入Excel文件?

我在R中创build了一个方法,它从测量中获取4个值,然后将它们保存到局部variables中,并将它们放置在matrix中,然后将该matrix写入Excel文件。 非常简单的概念,但是因为input是react native的..如果input多个调查,那么它只是覆盖了以前的调查..所以现在我需要一个计数器variables。 这里是代码的一些剪辑。

(在服务器类中)

surveyFinish <- eventReactive(input$click2,{`` state = input$UState happiness = input$UHap work = input$UWork env = input$UEnv surveyans <- paste(state, happiness, work, env, sep=" ") newMat = matrix( c(state, env, work, happiness), nrow = 1, ncol = 4, byrow = TRUE) writeWorksheetToFile("StateSurvey.xlsx", newMat, "SomeOtherSheet", z, 1, header = FALSE) write.table(newMat, "SurveyTab.txt", sep="\t") return() }) output$youSaid<- renderDataTable({ surveyFinish() }) 

(在UI中)

 tabPanel("Survey", textInput("UState", label = h2("Your State"), value = "State name"), numericInput("UHap", label = h2("Your Happiness"), value = "Enter a number from 1-10", min = 1, max = 10), numericInput("UEnv", label = h2("Your Environment"), value = "Enter a number from 1-10", min = 1, max = 10), numericInput("UWork", label = h2("Your Workload"), value = "Enter a number from 1-10", min = 1, max = 10), actionButton("click2", "Finish Survey!"), tableOutput("youSaid") ), 

每一个shiny的会议是独立的,因此你可能需要一个全局variables共享整个会话。 全局variables可以在global.R中定义在与server.R和ui.R相同的文件夹中。 这里更多的参考

或者,您可以使用他们提交的时间戳单独将调查结果写入单独的txt文件,然后在调查完成后立即读取所有调查结果,然后将最终结果写入Excel文件。