Reading in a file in R Shiny

So, I am creating an application in R shiny that requires the user to download a CSV file. After I read R shiny, I'm not sure how to actually manipulate this object for use. The general code syntax is as follows:

UI file:

#ui.R
# Define UI for random distribution application 
shinyUI(fluidPage(

  # Application title
  titlePanel("ORR Simulator"),

  # Sidebar with controls to select the random distribution type
  # and number of observations to generate. Note the use of the
  # br() element to introduce extra vertical spacing
  sidebarLayout(
    sidebarPanel(
          fileInput('file1', 'Select the XXX.csv file',
                accept=c('text/csv','text/comma-separated-values,text/plain','.csv')),
      tags$hr(),
          fileInput('file2', 'Select the YYY.csv file',
                accept=c('text/csv','text/comma-separated-values,text/plain','.csv')),
      tags$hr(),
     numericInput("S", "Number of simulations to run:", 100),

       mainPanel(
plotOutput("plot")
    )
  )
))

Server file:

#server.R
library(shiny)

shinyServer(function(input, output) {

text1 <- renderText({input$file1})
text2 <- renderText({input$file2})

file1 = read.csv(text1)
file2 = read.csv(text2)

output$plot <- renderPlot({

plot(file1[,1],file2[,2])

})


})

And so I was expecting text1 and text2 to contain lines containing the path to the file where the files are located, but that doesn't seem to be the case. Ultimatley I just want to be able to read in two data sets and from there be able to do analysis for output based on these two data sets.

Of course, using renderText might not be the right idea, so any suggestions on how to do this better are really appreciated.

+4
1

http://shiny.rstudio.com/gallery/file-upload.html. . , file$datapath, , NULL ( ).

server.R

#server.R
library(shiny)

shinyServer(function(input, output) {

    observe({
        file1 = input$file1
        file2 = input$file2
        if (is.null(file1) || is.null(file2)) {
            return(NULL)
        }
        data1 = read.csv(file1$datapath)
        data2 = read.csv(file2$datapath)
        output$plot <- renderPlot({
            plot(data1[,1],data2[,2])
        })
    })

})

ui.R

library(shiny)

#ui.R
# Define UI for random distribution application 
shinyUI(fluidPage(

    # Application title
    titlePanel("ORR Simulator"),

    # Sidebar with controls to select the random distribution type
    # and number of observations to generate. Note the use of the
    # br() element to introduce extra vertical spacing
    sidebarLayout(
        sidebarPanel(
            fileInput('file1', 'Select the XXX.csv file',
                      accept=c('text/csv','text/comma-separated-values,text/plain','.csv')),
            tags$hr(),
            fileInput('file2', 'Select the YYY.csv file',
                      accept=c('text/csv','text/comma-separated-values,text/plain','.csv')),
            tags$hr(),
            numericInput("S", "Number of simulations to run:", 100)
        ),
        mainPanel(
            plotOutput("plot")
        )
    ))
)
+4

All Articles