Monday, September 25, 2017

R Shiny: running a standalone browser window when calling runApp

Leave a Comment

I'm running a standalone R Shiny app on Windows in a browser by setting options(browser=path/to/browser/exe) and using shiny::runApp("path/to/app", launch.browser=TRUE). The browser to support is MSIE (default), but, if available, it can be also be Chrome or Firefox. My goal is to run the app as if using the --app= command line option for a standalone Chrome app, i.e. in a new browser window, which is stripped of the menubar and the toolbar, but preserves the titlebar (so not in the "kiosk" mode), and, if possible, without any other contents of the browser (like previously opened tabs or a home page). What's the best way to do that?

For instance, using JavaScript, one would call:

window.open("http://127.0.0.1:5555/", "MyApp", "menubar=no,toolbar=no,location=no"); 

which would do the job (+/- inconsistent support for location=no, i.e. disabling the address bar, which I can live with). Now, how to do it using R Shiny?

1 Answers

Answers 1

It's not very elegant, but you can start Internet Explorer by the COM interface using e.g. package RDCOMClient.

As the documentation states, the launch.browser argument can also be a function which is given the URL of the app, so we can create the object there:

library(RDCOMClient)  runApp("path/to/app",        launch.browser = function(shinyurl) {           ieapp <- COMCreate("InternetExplorer.Application")          ieapp[["MenuBar"]] = FALSE          ieapp[["StatusBar"]] = FALSE          ieapp[["ToolBar"]] = FALSE          ieapp[["Visible"]] = TRUE          ieapp$Navigate(shinyurl)          }) 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment