0

Im tring to create a shiny app that read and online onedrive xlsx file and show some things, but for the moment Im unable to read the onedrive xlsx file, I already explore the Microsoft365R and I can conect to my onedrive and I even can open the fil but... what it does is from r open a tab in chrome with the excel file.

I need the file in the local enviroment of r.. this its beacause the shiny app must be deploy in a web server, that every time the app runs it reads the update the file.

library(Microsfot365R)

odb <- get_business_onedrive()
odb$open_file("lcursos.xlsx")

Also this its a business account, so I also have to put the username and key to acces each file, that its beacause use the simple url doesnt work, it says Error 403 FORBIDEEN.

Any ideas? Thank you so much!

2 Answers2

0

Use the download_file() method to download the file to your local machine:

odb$download_file("lcursos.xlsx")

You can set the location of the download with the dest argument. Once it's downloaded, open it with the xls reader package of your choice. I suggest either openxlsx or readxl.

Note that if your file is password protected, your options are limited. See this question for possible solutions.

Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
  • There is a way to load directly into R? – MANUEL ALEJANDRO RODRIGUEZ ORT Sep 03 '21 at 12:56
  • What if I need to read the file inside a Shiny app deployed to shinyapps.io? The download_file option wouldn't work (it wouldn't know where to download things) and what is actually needed (as per question from Manuel) is to load the information directly into the environment instead of saving it somewhere and then load it. – Matteo Castagna Sep 03 '21 at 16:31
  • 1
    @MatteoCastagna every R session, even one running in shinyapps.io, has a filesystem available to it. Locating a file in that filesystem is an exercise left to the reader – Hong Ooi Sep 03 '21 at 16:37
  • Thanks for your answers. But how can I do a code login in the `get_business_onedrive()`, that its my issue with the solution given by @HongOoi, in my pc when I use the `get_business_onedrive()` funcition and it open a new tab and I allow the conection, but it dont work on the shinyapps.io. So how can I code the login using the Microsoft360R ? – MANUEL ALEJANDRO RODRIGUEZ ORT Sep 10 '21 at 16:26
  • @MANUELALEJANDRORODRIGUEZORT see my answer to Matteo [here](https://stackoverflow.com/a/69050422/474349) – Hong Ooi Sep 10 '21 at 20:33
0

In 2021, I was unable to do follow your answer, so I use Google googledrive library in that time to solve the problem. Now I face the same challenge, so I checking it, and I find the way to solve it.

Thanks

library(Microsoft365R)
library(AzureGraph)

od <- get_business_onedrive()
od$list_files()

dest <- tempfile(fileext = ".xlsx")

od$download_file("Documentos/lcursos.xlsx", dest=dest,overwrite = T)

open_in_r<-readxl::read_excel(dest)