New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to specify file format to support Shiny fileInput() #85

Closed
pofigster opened this Issue Apr 20, 2015 · 5 comments

Comments

Projects
None yet
6 participants
@pofigster

pofigster commented Apr 20, 2015

When a file is loaded through a fileInput() widget in a Shiny app, it appears that read_excel scans the file name to determine the file type (at least when input$file[,4] - the file path) is used. Shiny uploads an extension-less temporary file so read_excel can't open the file.

@Nihasa

This comment has been minimized.

Nihasa commented Apr 22, 2015

Hi, I ran into this problem as well and my current workaround is as follows:

           file.copy(inFile$datapath,
                      paste(inFile$datapath, ".xlsx", sep=""))
            read_excel(
                    paste(inFile$datapath, ".xlsx", sep=""), 1)

it's not the cleanest but it works.

@andrewcstewart

This comment has been minimized.

andrewcstewart commented May 16, 2015

thanks for the workaround @Nihasa

@faidherbard

This comment has been minimized.

faidherbard commented Jun 1, 2015

Hello,
This is not specific to readxl, I ran into the same issue with readr when I wanted to read_csv a zipped CSV file. readr does it right in my R scripts when it has the extension, but it fails with the extension-less temporary file uploaded by Shiny.

jirkalewandowski added a commit to jirkalewandowski/readxl that referenced this issue Jun 28, 2015

@0tertra

This comment has been minimized.

0tertra commented Jul 13, 2015

to ensure that the user does upload an .xlsx file, or you need to check the extension you're self to switch between read functions. You can extract the extension as following:

update: instead of file.copy() file.rename() can be used.

ext <- tools::file_ext(inFile$name)
 file.rename(inFile$datapath,
                   paste(inFile$datapath, ext, sep="."))
 read_excel(paste(inFile$datapath, ext, sep="."), 1)
@zross

This comment has been minimized.

zross commented Aug 20, 2015

I agree that adding the ability to feed read_excel() the extension would be useful, particularly in Shiny where the filename from fileInput drops the extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment