我正在尝试将csv文件加载到闪亮的程序,在适当的位置编辑它并下载已编辑的文件 . 我发现包 DT 提供了相同的功能 . 我修改example here从文件中读取csv,然后example here写入输出 . 我还尝试使用DT的实验功能here编辑加载的CSV . 我的下面的代码加载了csv,并保存了CSV,但在尝试编辑它时,它崩溃并出现错误:

Warning: Error in <<-: invalid (NULL) left side of assignment
Stack trace (innermost first):
65: observeEventHandler [/home/user/ShinyApp/EditingValues/server.R#40]

基本上,我的问题我相信我无法从example here中的读取csv向x提供值 .

我的 ui.R

fluidPage(
  titlePanel("Uploading Files"),
  sidebarLayout(
    sidebarPanel(
      fileInput('file1', 'Choose file to upload',
                accept = c(
                  'text/csv',
                  'text/comma-separated-values',
                  'text/tab-separated-values',
                  'text/plain',
                  '.csv',
                  '.tsv'
                )
      ),
      tags$hr(),
      checkboxInput('header', 'Header', TRUE),
      radioButtons('sep', 'Separator',
                   c(Comma=',',
                     Semicolon=';',
                     Tab='\t'),
                   ','),
      radioButtons('quote', 'Quote',
                   c(None='',
                     'Double Quote'='"',
                     'Single Quote'="'"),
                   '"'),
      tags$hr(),
      p('Once you are done download the  data'),
      downloadButton('x3', 'Download Data')
    ),
    mainPanel(
        DT::dataTableOutput('x1')
    )
  )
)

我的 server.R

# By default, the file size limit is 5MB. It can be changed by
# setting this option. Here we'll raise limit to 9MB.

# Install DT, experimental version may not work well 
# devtools::install_github('rstudio/DT@feature/editor')

library(shiny) # The main program
library(DT) # Edit the output
library(data.table) # Faster read and write

options(shiny.maxRequestSize = 9*1024^2)

function(input, output, session) {
   dataframe<-reactive({
        if (is.null(input$file1))
            return(NULL)  
       dta_types = fread(input$file1$datapath, header = input$header,
                         sep = input$sep, quote = input$quote, nrows = 0,
                         strip.white = TRUE, data.table = FALSE)
        data<-fread(input$file1$datapath, header = input$header,
                    sep = input$sep, quote = input$quote,
                    stringsAsFactors = FALSE, colClasses= rep("character", ncol(dta_types)))
        data
    })

  output$x3 = downloadHandler('mtcars-filtered.csv', content = function(file) {
      s = input$x1_rows_all
      write.csv(dataframe()[s, , drop = FALSE], file)
  })
  output$x1 = DT::renderDataTable(dataframe(), selection = 'none')

  proxy = dataTableProxy('x1')

  observeEvent(input$x1_cell_edit, {
      info = input$x1_cell_edit
      str(info)
      i = info$row
      j = info$col
      v = info$value
      dataframe()[i, j] <<- DT:::coerceValue(v, dataframe()[i, j])
      replaceData(proxy, dataframe(), resetPaging = FALSE)
  })
}

怎么能实现这一目标?我确信我错过了某处的简单任务 . 我试过了

x=dataframe()

之前

output $ x1 = DT :: renderDataTable(dataframe(),selection ='none')

并且使用x而不是dataframe()到处但是在加载之前崩溃应用程序 . 感谢您的投入 . 使用 rhandsontablesimilar问题也没有答案 .