R shiny: read a table from file and use it

后端 未结 1 567
不知归路
不知归路 2021-01-12 09:50

I want to read a data.frame from file and then use it for making plots later on. The problem is that when I read the data, it is part of an output Object and can not be used

相关标签:
1条回答
  • 2021-01-12 10:51

    Make use of the reactive function :

    Make the following changes in the server part of your App

    library(shiny)
    
    shinyServer(function(input, output) {
    
    mydata <- reactive({
    
    inFile <- input$file1
    
    if (is.null(inFile))
      return(NULL)
    
    tbl <- read.csv(inFile$datapath, header=input$header, sep=input$sep,  dec = input$dec)
    
    return(tbl)
    })
    
     output$table.output <- renderTable({
     mydata()
     })
    
     output$plot1 <- renderPlot({
      x <- mydata()[,1]
      plot(x)
     })
    })
    
    0 讨论(0)
提交回复
热议问题