A second editor in RStudio

Posted on October 17, 2020 by Stéphane Laurent
Tags: R, shiny, javascript

Last month, my package shinyMonacoEditor has been published on CRAN. This package provides a code editor as a Shiny app. It is powered by Monaco editor, an amazing JavaScript library better known for powering the Microsoft ‘VS code’ editor.

While developing this app I really had fun and I improved my modest JavaScript skills. It works fine but it is rather a proof of concept. Indeed, if you want to enjoy the Monaco editor, it is better to use ‘VS code’. Even though shinyMonacoEditor makes available some features in addition to the built-ins features of the Monaco editor, it is not an essential tool for code development.

Recently I developed two HTML widgets which also are code editors: aceEditor and monaco. They have less features than shinyMonacoEditor, because you cannot communicate with R from a HTML widget, and you cannot run a system command. For example, shinyMonacoEditor allows to reformat a C++ file with the help of the command line utility clang-format. Again, this is just a proof of concept; if you want a tool to prettify some code, I would rather recommend my package prettifyAddins (available on CRAN).

The HTML widgets are less funny but more practical. They really provide a second editor in RStudio: you can open them in the viewer pane and they don’t lock RStudio, contrary to a Shiny app.

The aceEditor widget is powered by Ace editor, the JavaScript library also used by RStudio. It has support for 150 languages (syntax highlighting and snippets). It provides diagnostics for JavaScript and CSS but those tools are now quite old and provide false positive errors for more modern usages. I added the possibility to prettify or reformat the code for some languages, with the help of Prettier.

The monaco widget is powered by Monaco editor. It has support for 50 languages, particularly good for JavaScript. I have not submitted it to CRAN yet. I submitted aceEditor last week but there is a more recent version in my Github repo. If you want to try it now, run:


The Ace diff editor is implemented in this version. It allows to highlight the differences between two files (if you want a tool to also merge two files, give a try to my other package shinyMergely, available on CRAN).