Shiny 上传数据,将列名放在radiobutton中,并以闪亮的颜色显示表格

Shiny 上传数据,将列名放在radiobutton中,并以闪亮的颜色显示表格,shiny,Shiny,我想上传一个.csv文件。然后,将单选按钮选项更新为上载文件的列名,然后通过该单选按钮选择要显示的列。问题是每当我运行代码时,它都会给我这个错误 p.S.1.在运行此应用程序之前,有没有办法读取数据?比如在另一个应用程序中 库(闪亮) ui=基本页面( fileInput('uploadedcsv','',accept='.csv'), 单选按钮( “第1栏”, “选择列”, 选择=”, 内联=T ), 单选按钮( “第2栏”, “选择列”, 选择=”, 内联=T ), dataTableOu

我想上传一个.csv文件。然后,将单选按钮选项更新为上载文件的列名,然后通过该单选按钮选择要显示的列。问题是每当我运行代码时,它都会给我这个错误

p.S.1.在运行此应用程序之前,有没有办法读取数据?比如在另一个应用程序中

库(闪亮)
ui=基本页面(
fileInput('uploadedcsv','',accept='.csv'),
单选按钮(
“第1栏”,
“选择列”,
选择=”,
内联=T
),
单选按钮(
“第2栏”,
“选择列”,
选择=”,
内联=T
),
dataTableOutput('mytable')
)
服务器=功能(会话、输入、输出){

zz是不可再设置的闭合:

z <- reactive(z[,c(input$column1,input$column2)])

z关于编码风格,使用renderDataTable,内部只有一个反应式似乎是多余的,我只需编写
output$mytable=renderDataTable({data()[,c(input$column1,input$column2)])
@shosaco谢谢。但是,我更喜欢Mike之前的答案。我这样编码是因为我的目标不是表格。我使用表格来查看数据的外观。后来,我在另一个函数中使用数据框来绘制图表
z <- reactive(z[,c(input$column1,input$column2)])
server = function(input, output, session) {

  # z is reactive to a change in the input data

  z <- reactive({
    infile <- input$uploadedcsv

    if (is.null(infile))
      return(NULL)

    read.csv(infile$datapath, header = TRUE, sep = ",")
  })

  observe({
    vchoices <- names(z())
    updateRadioButtons(session, "column1", choices = vchoices)
    updateRadioButtons(session, "column2", choices = vchoices)
  })

  # renderDataTable is reactive to a change in the input data
  # or the selected columns

  output$mytable = renderDataTable({
    z()[,c(input$column1, input$column2)]
  })
}