File uploads on Shiny Server now working

3,597 views
Skip to first unread message

Joe Cheng

unread,
Mar 5, 2013, 5:20:00 PM3/5/13
to shiny-...@googlegroups.com
Hi all,

Many of you have been waiting patiently for file upload improvements in Shiny, especially fixing file uploads on Shiny Server. We're pretty close now, but it involved writing a whole lot of new code so I'd like to see some beta testing before we release to CRAN.

Please help us beta test by following the upgrade instructions at the end of this message.

Features:
  • Now works with Shiny Server! (glimmer.rstudio.com is already upgraded)
  • Local uploads are also much faster and more robust
  • Progress is displayed during upload
Limitations:
  • (Still) not compatible with IE9 and earlier
  • Uploads cannot be canceled (other than reloading the page)
Note:
  • By default, Shiny limits file upload requests to 5MB; anything larger will be rejected. You can change this limit using option(shiny.maxRequestSize = x), where x is the size in bytes; a size of -1 means any size is allowed.
----

Instructions for upgrading a Shiny Server install:

Run these commands from the shell:

sudo su - -c "R -e \"install.packages('shiny', repos=c(RStudio='http://rstudio.org/_packages', CRAN='http://cran.rstudio.com'))\""


Then restart Shiny Server. If you're using Upstart, the command is sudo restart shiny-server


Instructions for upgrading a non-server Shiny install:

Run this command from the R console:

install.packages('shiny', repos=c(RStudio='http://rstudio.org/_packages', CRAN='http://cran.rstudio.com'))

Then restart your R session.

Glen DePalma

unread,
Mar 6, 2013, 12:42:05 AM3/6/13
to shiny-...@googlegroups.com
Hello Joe -

I am hosting an application on glimmer.rstudio.com but I still get the error.  From my understanding I don't have to do anything as it should already be upgraded but I still get the error message.


If you select load data in the top left corner and then select use a file on my local machine the error still occurs (it doesn't matter what file you select).

Thanks

Joe Cheng

unread,
Mar 6, 2013, 2:16:46 AM3/6/13
to shiny-...@googlegroups.com
Hi Glen, you had an older version of the shiny package installed in your personal library on glimmer (i.e. you installed shiny yourself from within RStudio or from a shell prompt). I removed it, it works now (or I assume it would, if I knew what kind of file to upload...).


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ajay Pillarisetti

unread,
Mar 8, 2013, 2:42:10 PM3/8/13
to shiny-...@googlegroups.com
Hi Joe -

This is awesome. I'm trying to write a little app that allows users to upload and process some CSVs of temperature traces. The app's on glimmer (http://glimmer.rstudio.com/ajayp/SUMS/). 

I'm noticing some very bizarre behavior -- the loaded csvs repeat the first ~81 lines twice and then print the whole file. I've attached here a sample csv and will paste some code in below for my file upload. When I upload the same csv to a directory on the server and access it through list.files, i don't run into any problems. Any thoughts, if time permits, would be greatly appreciated.

Ajay

server.r

  # Return the requested dataset
  datasetInput <- reactive({
if(input$dataset=="Upload a File"){
   inFile <- input$file1
   if (is.null(inFile))
     return(NULL)
   dataset<-read.csv(inFile$datapath, header=T, stringsAsFactors =F)
   #write.csv(dataset,file=paste("/home/ajayp/data/",inFile[1],sep=""))
}
else{
  filepath<-paste('/home/ajayp/data/',input$dataset,sep="")
    dataset<-read.csv(filepath,header=T,stringsAsFactor=F)
    }
  })

ui.r

  sidebarPanel(
  #select a dataset - doesn't dynamically reload? why??
    selectInput("dataset", "Choose a SUMS File:",
    choices = factor(c(list.files('/home/ajayp/data', pattern=".csv"),'Upload a File'))),
    conditionalPanel(
    condition = "input.dataset == 'Upload a File'",
    fileInput('file1', 'Choose CSV File',
            accept=c('text/csv')        
            )
    ),
...
)
sample.csv

Joe Cheng

unread,
Mar 8, 2013, 3:11:30 PM3/8/13
to shiny-...@googlegroups.com
Hmmm, I'm not seeing this behavior when I go to your link and upload the file you attached. I go to the "Raw Data" tab and all looks to be in order...?

Ajay Pillarisetti

unread,
Mar 8, 2013, 3:28:42 PM3/8/13
to shiny-...@googlegroups.com
Weird. I checked on three browsers (safari,ff,chrome) on OS X and two on Win7 (chrome,firefox) and got the same error. c&p'd what i see in raw data and attached here. the repetition's in there (from here). Thanks for looking at it - much appreciated.

raw_ouput.txt

Joe Cheng

unread,
Mar 11, 2013, 1:37:20 AM3/11/13
to shiny-...@googlegroups.com
I've tried again and couldn't repro--I must be misunderstanding. Can you give me exact repro steps?

I've noticed though that if you go to "Raw Data" and change the dataset, it doesn't work--you get a message saying syntax error in the JavaScript console. I tracked this down to a bug in RJSONIO, which I've reported to the maintainer with a suggested fix.


On Fri, Mar 8, 2013 at 12:28 PM, Ajay Pillarisetti <ajaypill...@gmail.com> wrote:
Weird. I checked on three browsers (safari,ff,chrome) on OS X and two on Win7 (chrome,firefox) and got the same error. c&p'd what i see in raw data and attached here. the repetition's in there (from here). Thanks for looking at it - much appreciated.


You received this message because you are subscribed to a topic in the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/shiny-discuss/rQMyQR7gOQk/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to shiny-discus...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ajay Pillarisetti

unread,
Mar 11, 2013, 1:41:43 PM3/11/13
to shiny-...@googlegroups.com
thanks again for looking at this. I'm finding the same glitch using the code from your upload tutorial (http://jcheng5.github.com/shiny/tutorial/#uploads). 

I set up a separate app on glimmer here:


and any CSV I upload does the same thing -- repeats after a (seemingly) arbitrary number of lines. I tried this with csvs output from a number of different places. tried importing them by ssh-ing into glimmer and running R from the command line -- they work fine there. Let me know what else, if anything, I can do to help.... and thanks.

Ajay

Joe Cheng

unread,
Mar 11, 2013, 1:49:19 PM3/11/13
to shiny-...@googlegroups.com
So if you go to this link:
http://glimmer.rstudio.com/ajayp/readCSV/

And upload the attached pressure.csv file, you're seeing something
other than 19 rows of data rendered in the UI?

On Mon, Mar 11, 2013 at 10:41 AM, Ajay Pillarisetti
pressure.csv

Ajay Pillarisetti

unread,
Mar 11, 2013, 1:59:09 PM3/11/13
to shiny-...@googlegroups.com
that works perfectly.

it seems, perhaps, to be a problem with large number of columns and rows. as an example, attached here is a 7 column / 200 row file with random uniforms. when I upload, it does some weird stuff periodically throughout the file (see attached pictures -- row 88, row 177).


runif.csv
error-row-89.png
error-row-177.png

Joe Cheng

unread,
Mar 11, 2013, 2:05:32 PM3/11/13
to shiny-...@googlegroups.com
Excellent, I can repro the problem now as well--thank you! I'll let
you know what I find.
>> <pressure.csv>

Joe Cheng

unread,
Mar 11, 2013, 2:27:01 PM3/11/13
to shiny-...@googlegroups.com
OK, I believe this is fixed. I've deployed the changes on glimmer, and
if you have your own Shiny Server deployed you can upgrade using "npm
install -g shiny-server" (the new version is 0.3.3).

Thanks for the feedback!

Ajay Pillarisetti

unread,
Mar 11, 2013, 4:05:51 PM3/11/13
to shiny-...@googlegroups.com
Thanks so much Joe -- works like a charm.

Andrew Clark

unread,
Mar 15, 2013, 12:48:35 PM3/15/13
to shiny-...@googlegroups.com
I'm missing something here.

 Works locally a dream but on glimmer I get the
"The application unexpectedly exited.

Diagnostic information has been dumped to the JavaScript error console."
error

The shiny version In my glimmer library is 0.4.1.99

Joe Cheng

unread,
Mar 15, 2013, 12:55:47 PM3/15/13
to shiny-...@googlegroups.com
You have an older version of shiny in your ~/R/library on glimmer. If you remove it and let your apps exit (by closing any browser windows that have them open, then waiting at least 5 seconds) then it should work the next time you try it.

Andrew Clark

unread,
Mar 15, 2013, 1:24:06 PM3/15/13
to shiny-...@googlegroups.com
Thanks
I tried clicking the x button in glimmer.rstudio to remove the earlier version but got
Error: could not find function "remove.packages"
 
Now when I go into glimmer.rstudio I get an R code execution error
and none of the packages are shown . in the console 
Error in as.data.frame(installed.packages(), stringsAsFactors = F) : 
  could not find function "installed.packages"

Joe Cheng

unread,
Mar 15, 2013, 2:14:01 PM3/15/13
to shiny-...@googlegroups.com
Wow, it almost sounds like your utils package is gone. Can you do Session | Restart R and see if that helps?

Andrew Clark

unread,
Mar 15, 2013, 2:21:22 PM3/15/13
to shiny-...@googlegroups.com
Yep. I inadvertently detached it by clicking on the checkbox. Restarting R has not helped nor has signing out and back in again

Joe Cheng

unread,
Mar 15, 2013, 2:33:49 PM3/15/13
to shiny-...@googlegroups.com
How about calling library(utils) from the RStudio console?

Andrew Clark

unread,
Mar 15, 2013, 2:40:08 PM3/15/13
to shiny-...@googlegroups.com
Thanks for suggestion
That worked. As does the uploading now
Sorry for wasting your time. Still I have learnt something :)

Joe Cheng

unread,
Mar 15, 2013, 3:29:09 PM3/15/13
to shiny-...@googlegroups.com
Happy to help :)

Daniel Schumann

unread,
Mar 28, 2013, 3:48:43 AM3/28/13
to shiny-...@googlegroups.com
Hi,

it sounds a bit cheeky, but is it possible to get the code of you csv upload, because this is exactly what I'm searching for.

Thanks in advance
Daniel

Joe Cheng

unread,
Mar 28, 2013, 5:09:23 PM3/28/13
to shiny-...@googlegroups.com
You can find it on your own system by typing this at the R console:

browseURL(system.file("examples/09_upload", package="shiny"))


zak gezon

unread,
Apr 1, 2013, 7:58:41 AM4/1/13
to shiny-...@googlegroups.com
Hi!

I am trying to make a simple app that lets a user upload some data to be subsetted and manipulated, etc, and then download the final product. So far I have not been able to get the data to upload in a way that will allow me to manipulate it.  When I upload data locally using either a file pathway or read.csv(file.choose()) everything works fine, so it is just a matter of getting the data to upload through glimmer.  Any help would be appreciated!  Here is a simplified version of what I am trying to do (and one version (of many) of what I have tried so far).  Thanks in advance! Pardon my ignorance, I have only been fiddling with shiny for a couple of days so far.  

Cheers,

Zak


ui.R
# define the sidebar
shinyUI(pageWithSidebar(
  
  # title
  headerPanel("Zak's RMBL bee label maker"),
  
  sidebarPanel(
    
    fileInput('file1', 'Choose CSV File',
              accept=c('text/csv', 'text/comma-separated-values,text/plain')),
    tags$hr(),
    downloadButton('downloadData', 'Download labels')
  ),
  
  mainPanel(
    tableOutput('table')
  )
  
))


server.R
# Define server logic
shinyServer(function(input, output) {
  
  # get the data
    
  d <- input$file1
  
  l<-matrix(nrow=(ceiling(length(d[,1])/11))*6,ncol=11) # make the empty matrix
  k<-1 # counter in the nested for loops below

  # make the insect labels from uploaded raw data
  for (j in ((c(1:(length(l[,1])/6))*6)-5)){
    for (i in c(1:11)) {  
      l[j,i]<-paste(d[k,9],"  USA: CO: Gunnison Co.")# bee number, county info
      l[j+1,i]<-paste("RMBL,",d[k,5],d[k,6]) #site info
      l[j+3,i]<-paste(d[k,2],d[1,1],", ",d[k,12]) # date and collector
      l[j+4,i]<-paste(d[k,11],d[k,10])
      l[j+5,i]<-paste("")

#####    more guts of the insect label maker that I have omitted for the sake of simplicity in this post   #####

  if (k < length(d[,1])) k<-k+1
    }
  }  
 
  # Show the values using an HTML table
  output$table <- renderTable({ 
   l                             
  })
  
  # allow the data to be downloaded
  output$downloadData <- downloadHandler(
    filename = function() { paste("bee labels", '.csv', sep='') },
    content = function(file) {
      write.csv(l, file)
    }
  )
})

 

On Tuesday, March 5, 2013 5:20:00 PM UTC-5, Joe Cheng [RStudio] wrote:

Joe Cheng

unread,
Apr 1, 2013, 1:12:39 PM4/1/13
to shiny-...@googlegroups.com
All of the code between the lines "shinyServer(function(input, output) {" and "# Show the values using an HTML table", needs to be wrapped up in a reactive. You're not allowed to read things off the "input" object unless you're doing it in a chunk of reactive code.

data <- reactive({
  if (is.null(input$file1)) {
    return(NULL)
  }
  d <- read.csv(input$file1$datapath)  # read the file
  # ... process your data ...
  l
})

Because it's wrapped in "reactive()", this code will execute as often as it needs to in order to stay up-to-date with respect to the inputs it uses. You can access the calculated value (in this case, the value of "l", since that's the last expression in the reactive) from output$table's and output$downloadData's render calls by calling "data()".


Zak Gezon

unread,
Apr 1, 2013, 2:09:28 PM4/1/13
to shiny-...@googlegroups.com
Excellent, it is working like a charm.  Thank you very much!

Zak


--
You received this message because you are subscribed to a topic in the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/shiny-discuss/rQMyQR7gOQk/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to shiny-discus...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Zak Gezon
PhD Candidate, Dartmouth College
78 College St.
Life Sciences Center
Biological Sciences Dept.
Hanover, NH  03755

Jessica Olsen

unread,
Apr 5, 2013, 4:44:02 PM4/5/13
to shiny-...@googlegroups.com
Hi Joe,

First of all, thanks for all that you're doing.  Shiny is so awesome!

I'm using the upload tutorial (http://jcheng5.github.io/shiny/tutorial/#uploads).  Initially, I was getting the same error as everyone else.  Ran the update and things were working pretty well with a small data set.  I've got a csv file with 15 columns.  I'm noticing that i get an error with anything more than about 200 rows.  The error appears in the loading progress slider bar and says "<html> <head> <title>An error has occurred</title> <link".  The full size of the file is 754x15 and about 149 KB, which is well under the 5MB size limit.

Have you ever encountered this problem?  Any ideas on a workaround?

Thanks!
Jess

Joe Cheng

unread,
Apr 5, 2013, 4:51:28 PM4/5/13
to shiny-...@googlegroups.com
Hi Jessica, that is quite surprising. Is this happening with Shiny Server, or Shiny running directly in your R session?


Jessica Olsen

unread,
Apr 5, 2013, 5:05:50 PM4/5/13
to shiny-...@googlegroups.com
Shiny Server.  I can get all the rows in with only 3 columns.  Anything more than that, and I get the same error.

Jessica Olsen

unread,
Apr 9, 2013, 2:47:54 PM4/9/13
to shiny-...@googlegroups.com
Any luck with this?

Thanks!
Jess

Joe Cheng

unread,
Apr 9, 2013, 2:49:47 PM4/9/13
to shiny-...@googlegroups.com, shiny-...@googlegroups.com

Can you see if it succeeds against this?

Jessica Olsen

unread,
Apr 11, 2013, 12:22:01 PM4/11/13
to shiny-...@googlegroups.com
Sorry if this is a repeat ... I think i sent a message just to you, Joe.  In any case ... your app worked great, and mine gave me the same error for a 149 KB csv file.  Any ideas?

How do i get an shiny app going on glimmer.rstudio.com?

Thanks,
Jess

Winston Chang

unread,
Apr 11, 2013, 2:05:30 PM4/11/13
to shiny-...@googlegroups.com
If you log into RStudio Server on glimmer at http://glimmer.rstudio.com:8787/ , create a directory called "ShinyApps" under your home directory. Then you can put your apps in there. For example, if you create a subdirectory called ~/ShinyApps/myapp, then you can access it at http://glimmer.rstudio.com/your_username/myapp/

-Winston

Joe Cheng

unread,
Apr 22, 2013, 5:34:05 PM4/22/13
to shiny-...@googlegroups.com, jessica....@gmail.com
Jessica, just wondering if you are still having this problem? I didn't receive any off-list e-mail from you--did you send it to j...@rstudio.com?

abhishek kapoor

unread,
Apr 25, 2014, 6:13:20 AM4/25/14
to shiny-...@googlegroups.com
Hi Joe

I'm trying to write a little app that allows users to upload and process some CSVs of brand by statement for correspondence map. 

I'm noticing some error--  I've attached here a sample csv and will paste some code in below for my file upload. Any thoughts, if time permits, would be greatly appreciated.


ui.r

library ("FactoMineR")
library ("shiny")
  shinyUI(pageWithSidebar(
    headerPanel("File input test"),
    sidebarPanel(
      fileInput("df", "File data", multiple=TRUE)
    ),
   
       mainPanel( # all of the output elements go in here
        h3("This is Correspondance Map"),
       
        plotOutput("caPlot")
       )
  ))

server.r


library (FactoMineR)
library (shiny)
shinyServer(function(input, output) {
     
  output$caPlot <- renderPlot({
    inFile <- input$df

    if (is.null(inFile))
      return(NULL)
    dataset<-read.csv(inFile$datapath, header=T, stringsAsFactors =F)
    ca2 = CA(dataset, graph = FALSE)
          plot(ca2)
     
    })
  })




Abhishek

CA_Worksheet.csv

Apsara Radhakrishnan

unread,
Dec 1, 2014, 2:56:15 AM12/1/14
to shiny-...@googlegroups.com
HI,

Thanks for listing these features, also can i know where does it upload the file. Is there any specific location or it is on the memory?
Appreciate your early response.

Thank you,
Apsara
Reply all
Reply to author
Forward
0 new messages