File upload example: How do I save the r dataframe

619 views
Skip to first unread message

Claudio Aguirre

unread,
Nov 12, 2014, 10:18:01 AM11/12/14
to shiny-...@googlegroups.com
Hi everybody,
I am really new to shiny and tried some examples of the gallery.
I am particularly interested in eth fiel upload, but I want to save the uploaded file as a R dataframe for later use.

Script of the upload (gallery example):

#server.R
library(shiny)

shinyServer(function(input, output) {
  output$contents <- renderTable({
    
    # input$file1 will be NULL initially. After the user selects
    # and uploads a file, it will be a data frame with 'name',
    # 'size', 'type', and 'datapath' columns. The 'datapath'
    # column will contain the local filenames where the data can
    # be found.

    inFile <- input$file1

    if (is.null(inFile))
      return(NULL)
    
    read.csv(inFile$datapath, header=input$header, sep=input$sep, 
				 quote=input$quote)
  })
})
# ui.R
library(shiny)

shinyUI(fluidPage(
  titlePanel("Uploading Files"),
  sidebarLayout(
    sidebarPanel(
      fileInput('file1', 'Choose CSV File',
                accept=c('text/csv', 
								 'text/comma-separated-values,text/plain', 
								 '.csv')),
      tags$hr(),
      checkboxInput('header', 'Header', TRUE),
      radioButtons('sep', 'Separator',
                   c(Comma=',',
                     Semicolon=';',
                     Tab='\t'),
                   ','),
      radioButtons('quote', 'Quote',
                   c(None='',
                     'Double Quote'='"',
                     'Single Quote'="'"),
                   '"')
    ),
    mainPanel(
      tableOutput('contents')
    )
  )
))

How can I achieve it?
I guess that I must use an action button but could not figure out how...
Any help.
thanks in advance

Huidong TIAN

unread,
Nov 14, 2014, 3:40:13 AM11/14/14
to shiny-...@googlegroups.com
dat <-  read.csv(inFile$datapath, header=input$header, sep=input$sep,
				 quote=input$quote)
save(dat, "path/dat.RData")
Reply all
Reply to author
Forward
0 new messages