Note
A setup guide by L. Abigail Walter
Instructions adapted from Travis Hinkelman
R Shiny Electron template created by Dirk Shumacher
Template & Instruction updated by Jinhwan Kim
For more info, see previous repository
Tip
For Windows, see this repository
Creating Standalone Apps from Shiny with Electron [2023, macOS M1]
Note
All of the following steps can be run exclusively in the RStudio Terminal (right to console).
so Terminal means Rstudio's terminal using Option + Shift + m
- Install R, Rstudio.
- Install Node.js: from offical page
- Install Electron Forge using
npm(npmis installed withNode.js) - In the Terminal, run
sudo npm i -g @electron-forge/cli, (sudorequires password)
Note
Check your versions of node and npm in Terminal with node -v, npm -v.
- Give Star ⭐, Fork this repository to your own account. Then clone it to your local PC
- Open an R project with cloned repository's
.Rprojfile. - In your project directory (may
Github/shiny-electron-template-m1), install Electron locally by runningnpx create-electron-app <APPNAME>.
Warning
You can not use app as <APPNAME>
Assume using myapp in this tutorial
- In your
myappfolder, deletesrcdirectory - Copy (or move) below files to your
myappfolder:
-
get-r-mac.sh: For install local R for electron app. -
add-cran-binary-pkgs.R: For install R packages into your project locally -
start-shiny.R: Let electron call your shiny app -
Folder shiny from this template, containing:
shiny/app.R: THIS IS YOUR SHINY APP'S CODE
-
Folder src from this template, containing:
- src/helpers.js
- src/index.css
- src/index.js
- src/loading.css
- src/loading.html
src/main.js: configure shiny electron app (likewidth,height)
- Change your directory to new app folder
cd myappwith Terminal
- Install local R with
sh ./get-r-mac.sh- First, check the version of R on your machine. In the R Console, run
version.
- First, check the version of R on your machine. In the R Console, run
Warning
Your PC's R version and electron's R version must same
- Build
app.Ras your application's code.
Note
not only app.R also other required files for shiny application (like /www)
-
If you don't have the
automagicpackage installed, runinstall.packages("automagic")in the console. -
In the Rstudio terminal, run
Rscript add-cran-binary-pkgs.Rto get packages for R.
Note
If your shiny application uses not-CRAN packages (like github / bioconductor), See Add not-CRAN packages below.
- Change
package.jsonas[fix] packages-json's content. And modify author information.
Note
Node package's version confirmed in 2024.01
-
Change
forge.config.jsas[fix] forge.config.js's content. -
Run
sudo npm installin Terminal to add new dependencies you listed inpackage.jsonto the node_modules folder.
Note
You need to run step after this, whenever you want to update shiny application.
-
Test your shiny application work by
electron-forge startin Terminal. -
If error occurs while
electron-forge makewithconf.dDeleter-mac/fontconfig/fonts/conf.d. see this issue -
If the app runs successfully, congratulations! Create the
.exe(as ZIP) on theelectron-forge makein Terminal. Your app can be found in the /out folder. (Strongly recommend to change read-only property with mac'sFinder)
- Raise an issue, please.
It doesn't affect to run shiny.
- manually copy library from your Local's R library to r-mac/library, You can check Local's R library with
.libPaths()in R console.
- First, change app.R code as basic example.
- If this works well, your app.R code has problem. In my case, I updated R package in shiny application but not in library of R-win directory.
- So update them with recent version, and try again will work.