反应性地将2个元素写入csv文件

时间:2015-04-05 17:18:52

标签: r csv shiny

我正在尝试编写用户在骰子投掷中获得的结果以及他在CSV文件中点击投掷按钮的时间,我可以在我自己的时间访问该文件。

我借用了以下示例中的代码(R/Shiny - How to write a .csv reactively including a actionButton?),但我无法合并多个被动操作。因为可以获取代码将结果写入csv文件,但是当我调用函数来获取开始时间时,我得到以下错误 - “在http://127.0.0.1:6949上收听 .getReactiveEnvironment()$ currentContext()中的错误:   没有活动的反应上下文,不允许操作。 (你试图做一些只能在反应性表达或观察者内部完成的事情。)“

rm(list = ls())
library(shiny)
a<-sample(c(1:6),1,replace=TRUE)

ui = pageWithSidebar(
  headerPanel('Min. working example - write a csv based on user input'),
  sidebarPanel(

    p("Include actionButton to prevent write occuring before user finalises selection"),  
    actionButton("generateButton","throw")),mainPanel(tableOutput("test1"))
)

server=(function(input, output) {

  getstart<-function(){

    if (input$runButton == 0) {return()} 
    else{
      v1<-Sys.time()
      g1<-as.character(v1) 
    }
    return(g1)

  }

  time<-getstart()
  b<-as.character(time)

  geodatasetInput <- observe({

    # Execute selections on data upon button-press
    if(input$generateButton == 0) {return()}
     else{

    AggSubGdata <- df
    write.csv(AggSubGdata
              , file = "solution21.csv"
              , row.names=F
    )
     }
  })
  output$test1<-renderText({
    if(input$generateButton==0){return(NULL)}
     else{
    a
     }
  })
})

runApp(list(ui = ui, server = server)) 

我试图将getstart()函数放在闪亮的body体外并触发它以使用全局变量触发它。我试图通过使用&lt;&lt; - operator来使用actionbuttion将值赋给此全局变量,但尝试不起作用。

1 个答案:

答案 0 :(得分:0)

我是开发人员。我有一个名为CSV Comp Framework的完整解决方案。 他做的事: 是一个数据库系统管理器(使用CQL的关系,CSV文件格式)+ CGI服务器。 适用于Linux,windows e windows ce。 桌面版是免费的(linux和windows).html示例:

    <html>
        <h1>Write your name and phone number with CSV Comp Framework</h1>
        <form action='http://server/cgi-bin/executa/default?'>
        Name:<br>
        <input type='text' name='ID-name'></a></p>

        Phone number:<br>
        <input type='text' name='ID-phone'></a></p>
        <!--CQL is another Query Language before Cassandra exists-->

        <input type='submit' name='YOUR_SCRIPT.cql'></a></p>
         </form>
        </html>

//the "YOUR_SCRIPT.cql" script CQL in cgi-bin
  {
   server-path/htdocs/YOUR_AGENDA;
   @adicionar;
   (ID-name;ID-phone);
   0;
   0;
   0;
   query=0;
   destino=0
   }

因此,您可以使用从桌面到服务器的关系,反之亦然