如何在Shinny R';s文件上传示例

如何在Shinny R';s文件上传示例,r,shiny,rstudio,shiny-server,R,Shiny,Rstudio,Shiny Server,我正在尝试创建我的第一个闪亮的R应用程序,它有两个功能: 显示用户上传的CSV文件 统计用户选择的行数 为了实现这些特性,我需要结合两个示例和,这涉及到将renderTable切换到renderDataTable。但是,我只能使用renderDataTable显示数据,但无法将callback和options等参数传递给它 这是server.R代码 renderDataTable的第一个参数应该是表达式。您需要将代码用大括号括起来,才能将第一段代码作为表达式传递: shinyServer(fun

我正在尝试创建我的第一个闪亮的R应用程序,它有两个功能:

  • 显示用户上传的CSV文件
  • 统计用户选择的行数
  • 为了实现这些特性,我需要结合两个示例和,这涉及到将
    renderTable
    切换到
    renderDataTable
    。但是,我只能使用
    renderDataTable
    显示数据,但无法将
    callback
    options
    等参数传递给它

    这是server.R代码
    renderDataTable
    的第一个参数应该是表达式。您需要将代码用大括号括起来,才能将第一段代码作为表达式传递:

    shinyServer(function(input, output) {
      output$contents <- renderDataTable({
        inFile <- input$file1
        if (is.null(inFile))
          return(NULL)
        subset(read.csv(inFile$datapath, header=input$header, sep=input$sep, quote=input$quote), select=input$show_vars)
      }
      , options = list(pageLength = 10),
      , callback = "function(table) {
             table.on('click.dt', 'tr', function() {
               $(this).toggleClass('selected');
               Shiny.onInputChange('rows',
                                   table.rows('.selected').indexes().toArray());
             });
           }"
      )
    })
    
    shinyServer(功能(输入、输出){
    
    output$contents感谢它工作得很好。我想我的下一步是修改回调函数。有没有关于在Shinny R中包装JavaScript函数的参考书?(或者我想使用jQuery修改DOM会容易得多)。我认为当前的javascript看起来可以计算用户选择的行数。
    server.R
    中将提供一个闪亮的变量
    input$rows
    。它是一个包含用户选择行的索引的向量。然后,用户选择的行数将是
    length(input$rows)
    。是的,我同意。但我的数据有一个名为“研究”,它有多个记录。所以我需要选择同一研究中的所有记录。我可以在jQuery中轻松地完成这项工作,但需要在Shiny R中找到解决方案。谢谢。
    shinyServer(function(input, output) {
      output$contents <- renderDataTable(
        inFile <- input$file1
        if (is.null(inFile))
          return(NULL)
       subset(read.csv(inFile$datapath, header=input$header, sep=input$sep, quote=input$quote), select=input$show_vars),
       options = list(pageLength = 10),
       callback = "function(table) {
             table.on('click.dt', 'tr', function() {
               $(this).toggleClass('selected');
               Shiny.onInputChange('rows',
                                   table.rows('.selected').indexes().toArray());
             });
           }"
      )
    })
    
    shinyServer(function(input, output) {
      output$contents <- renderDataTable({
        inFile <- input$file1
        if (is.null(inFile))
          return(NULL)
        subset(read.csv(inFile$datapath, header=input$header, sep=input$sep, quote=input$quote), select=input$show_vars)
      }
      , options = list(pageLength = 10),
      , callback = "function(table) {
             table.on('click.dt', 'tr', function() {
               $(this).toggleClass('selected');
               Shiny.onInputChange('rows',
                                   table.rows('.selected').indexes().toArray());
             });
           }"
      )
    })