Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
上传文件并使其在R中成为全局文件_R_Shiny - Fatal编程技术网

上传文件并使其在R中成为全局文件

上传文件并使其在R中成为全局文件,r,shiny,R,Shiny,我将一个文件上传到shiny(csv或excel),然后用文件数据创建一个对象。我希望这个对象是全局的,因为我在不同的输出中使用数据 我的原始(简化)服务器.R代码是: shinyServer(function(input, output) { output$contents <- renderTable({ inFile <- input$file1 if (is.null(inFile)) return(NULL) data <- read.c

我将一个文件上传到shiny(csv或excel),然后用文件数据创建一个对象。我希望这个对象是全局的,因为我在不同的输出中使用数据

我的原始(简化)服务器.R代码是:

shinyServer(function(input, output) {

  output$contents <- renderTable({

    inFile <- input$file1 
    if (is.null(inFile))
  return(NULL)
data <- read.csv(inFile$datapath, header = input$header, sep = input$sep,       quote = input$quote, dec = ".")

 data

  })

  output$grafic <- renderPlot({

    inFile <- input$file1
    if (is.null(inFile))
      return(NULL)

     data <- read.csv(inFile$datapath, header = input$header, sep = input$sep, quote = input$quote, dec = ".")

    barplot(table(data$SEVERIDAD), main="Severitat dels riscos detectats")

      })
})
shinyServer(功能(输入、输出){

output$contents为数据创建一个反应式表达式,然后在以后使用它实现所有功能…注意代码未经测试,仅用于本地使用(如果有效,请告诉我)…对于全局实现,您可以使用

    inFile <- input$file1 
    if (is.null(inFile))
      return(NULL)
    data <- read.csv(inFile$datapath, header = input$header, sep = input$sep,       quote = input$quote, dec = ".")


shinyServer(function(input, output) {

data <- reactive(data)
  output$contents <- renderTable({

data <- data()
data

  })

  output$grafic <- renderPlot({

     data <- data()

    barplot(table(data$SEVERIDAD), main="Severitat dels riscos detectats")

      })
})
shinyServer(function(input, output) {

  # Read the file into my_data, storing the data in this variable
  my_data <- reactive({
    inFile <- input$file1 
    if (is.null(inFile))
      return(NULL)
    data <- read.csv(inFile$datapath, header = input$header, sep = input$sep,quote = input$quote, dec = ".")
    data
  })
  # Create the table
  output$contents <- renderTable({
    my_data()
  })
  # Create a plot
  output$grafic <- renderPlot({    
    barplot(table(my_data()$SEVERIDAD), main="Severitat dels riscos detectats")

  })
})