Running RStudio Server/Workbench as a desktop app on macOS

Introduction

In my work as an R consultant/scientist, I often work on/with RStudio Server (soon to be RStudio Workbench) instances. These have several advantages:

However, there is also (at least) one downside: it runs in a browser (tab). This comes with the issue that the keybindings of your browser of choice will conflict RStudio’s keybindings. Using keybindings is a great way to improve productivity and increase working experience in general, not only in RStudio.

Probably the most annoying conflict is the ⌘ + W keybinding:

With the recent addition of the command palette in RStudio >= 1.4, the hotkey ⌘ + ⇧ + P does not work in Firefox - there it opens a new private window (and the hotkeys in Firefox cannot be changed).

Such keybinding conflicts apply to all applications which run in the browser, not solely to RStudio. Also without a dedicated desktop app for such applications, these will likely get lost among other browser tabs - most often, one has more than one (five, ten, twenty, etc.) tabs open.

To me, there is only one solutions to this: run these web apps as dedicated desktop apps.

RStudio Server desktop app options

In fact, there are different options to do this for RStudio (and more generic ones about which I will talk later):

Unless you’re working at a company which has lots of money to spare for many RStudio Desktop Pro licenses, you probably want to use RSwitch for this task. So did I for quite some time. RSwitch is great and does not only provide the option to connect to RStudio Server sessions but also let’s you easily switch between (CRAN) R versions on macOS.

However, the RSwitch implementation also lacks some features which limit the experience:

Nevertheless it solves the most important issues: the keybinding conflicts with browsers and loosing the instance between all other browser tabs.

The first points are a showstopper for people developing shiny apps or wanting to preview {pkgdown} or other interactive websites frequently. All in all, the experience feels limited for some people which do not make that heavy use of keybindings.

Because I am working in the consulting business since one year, I know that suggesting half-baked solutions to clients won’t make them happy in the long run (which does not mean that RSwitch is bad - I think it is a great peace of software, especially because it is FOSS!).

So I was wondering if more sophisticated solutions exist to this problem - and yes, they do!

Site-specific-browser (SBB) tools

Electron

You might have heard of Electron, a Javascript-based platform to run/wrap pretty much any app into a desktop app. Many apps make use of Electron to easily provide desktop apps, especially on Linux (Slack, Discord, Notion, Mattermost, VSCode). Electron apps are essentially a wrapper around a web app. While this is a great effort in general, Electron apps are also quite energy demanding. And they do not allow generic wrapping of any website.

And after doing more research, I found Unite / Coherence X.

Unite / Coherence X

These apps make it possible to pack any web app into a dedicated desktop app. While Unite uses Safari for this, Coherence relies on chromium-based browser solutions. The downside is that both are not free - but paying 20$ for an app which such universal capabilities that makes dev life so much easier is money well spent in my view. Also as usual there is a trial version to play around for free and evaluate if the tool is making life easier.

The developers also claim that both apps (especially Unite) use way less resources as their Electron counterparts. This is not surprising as Safari is well known to be highly optimized in terms of resource usage. I am not sure how the chromium-focused Coherence app compares here but given that Electron is quite a resource beast, it might also be lighter. One can even think of outsourcing all RStudio tasks to a remote instance this way (as long as you have internet access) because the local RStudio Desktop installation is quite resource hungry (and not really fast).

Now let’s inspect the RStudio Unite wrapper (I went for Unite instead of Coherence due to less resource and size needs) in more detail: One can set custom dock icons, configure the app behavior and style and optionally open multiple instances in the same app.

RStudio Workbench wrapped in Unite

Unite: Behavior setting

An important setting in my view is to set the whitelist setting as follows:

Only allow the website of RStudio Server to open in the app and force all other URLs to be opened in your default browser. Otherwise, URLs opened in RStudio Server (e.g. usethis::browse_github() or pkgdown::preview_site()) will open in the Unite app - whereas you probably want them in your default browser.

Unite Whitelist setting

Another neat detail is that one can set a custom dock icon for these apps. To have a visual difference to the RStudio Desktop app, I used the gray RStudio Logo:

RStudio Unite dock icon

I am not yet sure if I want to wrap all RStudio Server instances into a single app or create a dedicated one for each one. Both approaches have their pros and cons.

All in all, this discovery is really a game changer for me. I hope it can also be one for you :-)