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 macOS, 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 Alt + Shift + m
Also, I recommend to run Rstudio as Administrator.
-
Install R, Rstudio.
-
Install Node.js: from offical page
-
Install Electron Forge using
npm
(npm
is installed withNode.js
) -
In the Terminal, run
sudo npm i -g @electron-forge/cli
, (sudo
requires password) If you have trouble trynpm install --save-dev @electron-forge/cli
-
Install Innoextract from this link (Windows Only) and move it to program files and add Environment variable PATH (See this)
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
.Rproj
file. - In your project directory (may
Github/shiny-electron-template-windows
), 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
myapp
folder, deletesrc
directory - Copy (or move) below files to your
myapp
folder:
-
get-r-win.sh
: This installs a "local" R, that will be used by the 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, replace this with your app's code and other files like /www
-
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 myapp
with Terminal
- Install local R with
sh ./get-r-win.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, so if template's version is not same, you have to change as proper url
You may see URL (cloud.r-project.org/bin/windows/base/
) which shows latest version of R.
and if you move your mouse to Download R-4.4.2 for ...
you can see URL of it on the left bottom and you can use it to .sh
file
- Build
app.R
as your application's code.
Note
not only app.R
also other required files for shiny application (like /www
)
-
If you don't have the
automagic
package installed, runinstall.packages("automagic")
in the console. -
In the Rstudio terminal, run
Rscript add-cran-binary-pkgs.R
to get packages for R.
Note
If your shiny application uses not-CRAN packages (like github
/ bioconductor
), See Add not-CRAN packages below.
- Change
package.json
as[fix] packages-json
's content. And modify author information. (not merge)
Note
Node package's version confirmed in 2024.11
-
Change
forge.config.js
as[fix] forge.config.js
's content. (not merge) -
Run
npm install
in Terminal to add new dependencies you listed inpackage.json
to 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 start
in Terminal.
- If the app runs successfully, congratulations! Create the
.exe
(as ZIP) on theelectron-forge make
in Terminal. Your app can be found in the /out folder. (Strongly recommend to open with Administrator)
- Raise an issue, please.
It doesn't affect to run shiny.
- manually copy library from your Local's R library to r-win/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.