Azure / Microsoft365R

R SDK for interacting with Microsoft 365 APIs
Other
313 stars 44 forks source link

open_item() and open() do not work on remote server #139

Closed zhengzheli closed 1 year ago

zhengzheli commented 1 year ago

They work fine locally. The situation seems to be similar to that reported here with browseURL. Are these functions using browseURL behind the scenes? In the logs of remote server I get a message similar to below:

Please point your browser to the following url: https://test.sharepoint.com/sites/Test/Shared%20Documents/Test.pdf

As a workaround I was able to use shinyjs

hongooi73 commented 1 year ago

Correct, these functions are using browseURL. The online help should indicate this:

open(): Open the item in your browser.

Can you give me more info on your use case? I'm very leery of dragging Shiny in as a dependency, or adding custom JS code.

zhengzheli commented 1 year ago

Thanks for your response. I was originally using it to try and open a file on the document library of a SharePoint site. e.g.

documentLibrary <- sharepointSite$get_drive("Documents")
documentLibrary$open_item(sharepointFullPath)

That didn't seem to work, so I used shinyjs to run the following js:

js_code <- "
shinyjs.browseURL = function(url) {
  window.open(url,'_blank');
}"

However, now I am not using the sharepoint document library but using a onedrive document library instead, which is working well.

documentLibrary <- user$get_drive()
documentLibrary$get_item(path)$open()

So currently don't need this issue to be fixed. Thanks.

hongooi73 commented 1 year ago

That's very strange. Sharepoint and Business Onedrive use the same backend, so it should either work with both, or fail with both.

To clarify, are you running your R code on your own machine? Or in a remote session, eg in an Rstudio Cloud workspace?

zhengzheli commented 1 year ago

On a remote session, a Shiny server. But testing on local machine. Actually I haven't tested it lately; it was a while ago, and quite possibly there was something wrong with my earlier test. Thanks for your response.

hongooi73 commented 1 year ago

Basically if you're running your code on your local machine, then open() will work. Otherwise, it won't, as base R doesn't know how to open a browser in that case.