Packaging your Shiny App as an Windows desktop app
2015-03-25 11:57
162 查看
In developing SkyScorer I've sought ways to package it as a standalone Windows app. The advantages of doing this is quite clear:
The end-user doesn't need any R knowledge to run the app
The app can be distributed as a simple download
In this tutorial I will go through the process that is needed to create a standalone Windows Shiny app.
Portable R: http://sourceforge.net/projects/rportable/ Portable Chrome: http://portableapps.com/apps/internet/google_chrome_portable
Once you have downloaded the installation files for Portable R and Portable Chrome just install them and note down their installation path. We will use this later.
For simplicity I will assume you can make a folder in your C Drive called YourApp, but the folder could be situated anywhere. Now copy the portable R installation and the Portable Chrome installation into the C:\YourApp folder. Also copy your Shiny folder
containing server.R and ui.R (or a sole app.R in the case of single file Shiny app) into the folder. So now you should have three folders in your C:\YourApp directory
C:\YourApp\GoogleChromePortable
C:\YourApp\R-Portable
C:\YourApp\Shiny
AdditionalParameters= --app="http://localhost:8888"
The additional parameter there makes Chrome start up in app model (i.e. with address bar, bookmarks etc) which makes it look more like a native app.
run.vbs
runShinyApp.R
The contents
view raw
run.vbs hosted with ❤ by
GitHub
view raw
runShinyApp.R hosted with ❤ by
GitHub
Now WAIT! Don't click on run.vbs just yet! I advise you to add the following to the server.R inside the shinyServer(function(input, output,
session) { ... }). Please make sure you pass session as the third argument! The code you need to add is
view raw
session.r hosted with ❤ by
GitHub
This will close the Rsession when you close the browser (in this case Portable Chrome). Now clicking on run.vbs should start your app!
Simply zip up your folder C:\YourApp and distribute! Your users need only double click on run.vbs to run the app.
If you want to appear more professional you can follow the instruction in the next section to create a setup.exe file for you app.
InnoSetup will package everything in the directory into an .exe file which acts as a setup wizard.
I chose my default install path to be somewhere other than C:\Program Files as I have found a few issues with it on Windows 8 (no problem on Windows XP).
Once you are done with the InnoSetup Wizard you should end up with a .iss file looking like this
The code in the .iss file should be self-explanatory. I only added a few lines which I thought was helpful. Under
[setup] add PrivilegesRequired=none, this will not request for admin privilege when installing the app so should allow the app to be installed by most users. Also I created a shortcut to the desktop using the below
[Icons]
Name: "{commondesktop}\YourApp"; Filename: "{app}\Apps\run.vbs"; IconFilename: {app}\Your.ico
Of course I have my own custom .ico file to make the shortcut look unique and professional.
Hope this helps!
The end-user doesn't need any R knowledge to run the app
The app can be distributed as a simple download
In this tutorial I will go through the process that is needed to create a standalone Windows Shiny app.
Portable R & Chrome
Firstly download Portable R and Portable Chrome. These will serve as the backbone of our app. Essentially, we are packing along with our app self-contained copies of R and Chrome:Portable R: http://sourceforge.net/projects/rportable/ Portable Chrome: http://portableapps.com/apps/internet/google_chrome_portable
Once you have downloaded the installation files for Portable R and Portable Chrome just install them and note down their installation path. We will use this later.
For simplicity I will assume you can make a folder in your C Drive called YourApp, but the folder could be situated anywhere. Now copy the portable R installation and the Portable Chrome installation into the C:\YourApp folder. Also copy your Shiny folder
containing server.R and ui.R (or a sole app.R in the case of single file Shiny app) into the folder. So now you should have three folders in your C:\YourApp directory
C:\YourApp\GoogleChromePortable
C:\YourApp\R-Portable
C:\YourApp\Shiny
Setting Up Portable R
Just run R-Portable.exe and install all the libraries that are needed by your Shiny app. They will be stored in the Portable R folder.Setting Up Portable Chrome
Make sure you have the following line in the GoogleChromePortable.ini file which is in the GoogleChromePortable folderAdditionalParameters= --app="http://localhost:8888"
The additional parameter there makes Chrome start up in app model (i.e. with address bar, bookmarks etc) which makes it look more like a native app.
The .bat and .vbs files
In the C:\YourApp folder create two filesrun.vbs
runShinyApp.R
The contents
12 | Randomize CreateObject("Wscript.Shell").Run "R-Portable\App\R-Portable\bin\R.exe CMD BATCH --vanilla --slave runShinyApp.R" & " " & RND & " ", 0, False |
run.vbs hosted with ❤ by
GitHub
12345 | .libPaths("./R-Portable/App/R-Portable/library") # the path to portable chrome browser.path = file.path(getwd(),"GoogleChromePortable/GoogleChromePortable.exe") options(browser = browser.path) shiny::runApp("./Shiny/",port=8888,launch.browser=TRUE) |
runShinyApp.R hosted with ❤ by
GitHub
Now WAIT! Don't click on run.vbs just yet! I advise you to add the following to the server.R inside the shinyServer(function(input, output,
session) { ... }). Please make sure you pass session as the third argument! The code you need to add is
1234567891011 | shinyServer(function(input, output, session) { ... }) { # ... your other server code here # close the R session when Chrome closes session$onSessionEnded(function() { stopApp() q("no") }) # ... your other server code here } |
session.r hosted with ❤ by
GitHub
This will close the Rsession when you close the browser (in this case Portable Chrome). Now clicking on run.vbs should start your app!
Simply zip up your folder C:\YourApp and distribute! Your users need only double click on run.vbs to run the app.
If you want to appear more professional you can follow the instruction in the next section to create a setup.exe file for you app.
InnoSetup
Download InnoSetup http://www.jrsoftware.org/isdl.php and install the software and run the Wizard for creating a new setup file. Everything should be pretty self-explanatory, just make sure that InnoSetup knows to use the C:\YourApp directory. BasicallyInnoSetup will package everything in the directory into an .exe file which acts as a setup wizard.
I chose my default install path to be somewhere other than C:\Program Files as I have found a few issues with it on Windows 8 (no problem on Windows XP).
Once you are done with the InnoSetup Wizard you should end up with a .iss file looking like this
The code in the .iss file should be self-explanatory. I only added a few lines which I thought was helpful. Under
[setup] add PrivilegesRequired=none, this will not request for admin privilege when installing the app so should allow the app to be installed by most users. Also I created a shortcut to the desktop using the below
[Icons]
Name: "{commondesktop}\YourApp"; Filename: "{app}\Apps\run.vbs"; IconFilename: {app}\Your.ico
Of course I have my own custom .ico file to make the shortcut look unique and professional.
Hope this helps!
相关文章推荐
- 10 minutes to run every Windows app on your Ubuntu desktop,10分钟在你的UBUNTU中运行WINDOWS应用程序
- Use ILDASM.exe as an external tool in your VS2008
- 病毒-Run a DLL as an APP
- 解决在iTunes Connect 创建App时出现There was an error creating your Bundle ID.
- windows上zend server安装 报The server encountered an internal error or misconfiguration and was unable to complete your request -解决方法 摘自网络
- 【转】Windows 8 desktop app中dll搜索路径设置的诡异现象,Bug?
- 弹出run a dll as an app对话框&关机蓝屏的解决方法
- How to increase Memory usage for an App in Windows Phone
- Windows Phone Dev Center - How to create your first app for Windows Phone
- Windows 8 desktop app中dll搜索路径设置的诡异现象,Bug?
- 数据执行保护-run a dll as an app
- 关于run a dll as an app的问题
- How to Run a Program as an Administrator in Windows 7
- How to Run a Program as an Administrator in Windows 7
- Start Your Windows Programs From An NT Service
- How to drag a virtual file from your app into Windows Explorer
- 病毒-Run a DLL as an APP
- Let your installer run as an administrator
- Distributing your Application as an executable JAR file
- How to Run a Program as an Administrator in Windows 7