用R键上传后编辑数据帧

用R键上传后编辑数据帧,r,shiny,edit,import-from-csv,R,Shiny,Edit,Import From Csv,我构建了一个闪亮的应用程序,它接收用户上传的CSV文件并向其中添加标题 和两个新的列,以便以后进行一些计算 上载的CSV文件包含以下两列: 1 0.21 1 0.20 1 0.23 2 0.40 2 0.42 2 ... 要上载文件,我使用以下代码(正在运行): 在R会话中,我将使用以下代码: data1<- read.csv(file=inFile$datapath,header =input$header,sep=input$sep) colnames(data1)

我构建了一个闪亮的应用程序,它接收用户上传的CSV文件并向其中添加标题 和两个新的列,以便以后进行一些计算

上载的CSV文件包含以下两列:

1  0.21
1  0.20
1  0.23
2  0.40
2  0.42
2 ...
要上载文件,我使用以下代码(正在运行):

在R会话中,我将使用以下代码:

  data1<- read.csv(file=inFile$datapath,header =input$header,sep=input$sep)
  colnames(data1) <-c("Dose","Response")
  data1$ResponseLog <- log10(data1$Response + 1)
  data1$ResponseSqRoot <- sqrt(data1$Response + 1)

data1希望这有帮助:我也添加了一个按钮

rm(list = ls())
library(shiny)

ui = fluidPage(
    sidebarPanel(
      fileInput('file1', 'Choose file to upload',accept = c('text/csv','text/comma-separated-values','text/tab-separated-values','text/plain','.csv','.tsv')),
      checkboxInput('header', 'Header', TRUE),
      radioButtons('sep', 'Separator',c(Comma=',',Semicolon=';',Tab='\t'),'Comma'),
      radioButtons('quote', 'Quote',c(None='','Double Quote'='"','Single Quote'="'"),'Double Quote'),
      actionButton("Load", "Load the File"),width = 3),
    mainPanel(tableOutput("my_output_data"))
)

server = function(input, output) {

  data1 <- reactive({
    if(input$Load == 0){return()}
    inFile <- input$file1
    if (is.null(inFile)){return(NULL)}

    isolate({ 
    input$Load
    my_data <- read.csv(inFile$datapath, header = input$header,sep = input$sep, quote = input$quote,stringsAsFactors =FALSE)
    colnames(my_data) <-c("Dose","Response")
    my_data$ResponseLog <- log10(my_data$Response + 1)
    my_data$ResponseSqRoot <- sqrt(my_data$Response + 1)
    })
    my_data
  })
  output$my_output_data <- renderTable({data1()},include.rownames=FALSE)  

}
runApp(list(ui = ui, server = server))
rm(list=ls())
图书馆(闪亮)
ui=fluidPage(
侧栏面板(
fileInput('file1','Choose file to upload',accept=c('text/csv','text/逗号分隔值','text/tab分隔值','text/plain','.csv','.tsv')),
checkboxInput('header','header',TRUE),
单选按钮('sep','Separator',c(逗号=',',分号=';',制表符='\t'),'Comma'),
单选按钮('quote','quote',c(无='','Double quote'=''''','Single quote'=''”,'Double quote'),
actionButton(“加载”、“加载文件”),宽度=3),
主面板(tableOutput(“我的输出数据”))
)
服务器=功能(输入、输出){

data1查看这个问题-我想这可能会有所帮助,首先我使用
reactiveFileReader()上传文件
然后我创建一个新对象,允许我修改dataframe。我说得对吗?基本上是的,你会用正确的列名创建data.frame。然后你会反应性地将上传的数据添加到列中。然后你可以进行任何计算等。非常感谢你。这完美地解决了问题。很高兴为你提供帮助浏览主页上的教程
  data1<- read.csv(file=inFile$datapath,header =input$header,sep=input$sep)
  colnames(data1) <-c("Dose","Response")
  data1$ResponseLog <- log10(data1$Response + 1)
  data1$ResponseSqRoot <- sqrt(data1$Response + 1)
rm(list = ls())
library(shiny)

ui = fluidPage(
    sidebarPanel(
      fileInput('file1', 'Choose file to upload',accept = c('text/csv','text/comma-separated-values','text/tab-separated-values','text/plain','.csv','.tsv')),
      checkboxInput('header', 'Header', TRUE),
      radioButtons('sep', 'Separator',c(Comma=',',Semicolon=';',Tab='\t'),'Comma'),
      radioButtons('quote', 'Quote',c(None='','Double Quote'='"','Single Quote'="'"),'Double Quote'),
      actionButton("Load", "Load the File"),width = 3),
    mainPanel(tableOutput("my_output_data"))
)

server = function(input, output) {

  data1 <- reactive({
    if(input$Load == 0){return()}
    inFile <- input$file1
    if (is.null(inFile)){return(NULL)}

    isolate({ 
    input$Load
    my_data <- read.csv(inFile$datapath, header = input$header,sep = input$sep, quote = input$quote,stringsAsFactors =FALSE)
    colnames(my_data) <-c("Dose","Response")
    my_data$ResponseLog <- log10(my_data$Response + 1)
    my_data$ResponseSqRoot <- sqrt(my_data$Response + 1)
    })
    my_data
  })
  output$my_output_data <- renderTable({data1()},include.rownames=FALSE)  

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